1 21 22 package org.dbunit.database.statement; 23 24 import org.dbunit.dataset.ITable; 25 import org.dbunit.dataset.datatype.DataType; 26 import org.dbunit.dataset.datatype.TypeCastException; 27 28 import java.sql.Connection ; 29 import java.sql.SQLException ; 30 31 36 public class PreparedBatchStatement extends AbstractPreparedBatchStatement 37 { 38 private int _index; 39 40 PreparedBatchStatement(String sql, Connection connection) 41 throws SQLException 42 { 43 super(sql, connection); 44 _index = 0; 45 } 46 47 50 public void addValue(Object value, DataType dataType) 51 throws TypeCastException, SQLException 52 { 53 if (value == null || value == ITable.NO_VALUE) 55 { 56 _statement.setNull(++_index, dataType.getSqlType()); 57 return; 58 } 59 60 dataType.setSqlValue(value, ++_index, _statement); 61 } 62 63 public void addBatch() throws SQLException 64 { 65 _statement.addBatch(); 66 _index = 0; 67 } 68 69 public int executeBatch() throws SQLException 70 { 71 int[] results = _statement.executeBatch(); 72 int result = 0; 73 for (int i = 0; i < results.length; i++) 74 { 75 result += results[i]; 76 } 77 return result; 78 } 79 80 public void clearBatch() throws SQLException 81 { 82 _statement.clearBatch(); 84 } 85 } 86 87 88 89 90 91 92 93 | Popular Tags |