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 SimplePreparedStatement extends AbstractPreparedBatchStatement 37 { 38 private int _index; 39 private int _result; 40 41 public SimplePreparedStatement(String sql, Connection connection) 42 throws SQLException 43 { 44 super(sql, connection); 45 _index = 0; 46 _result = 0; 47 } 48 49 52 public void addValue(Object value, DataType dataType) 53 throws TypeCastException, SQLException 54 { 55 if (value == null || value == ITable.NO_VALUE) 57 { 58 _statement.setNull(++_index, dataType.getSqlType()); 59 return; 60 } 61 62 dataType.setSqlValue(value, ++_index, _statement); 63 } 64 65 public void addBatch() throws SQLException 66 { 67 boolean result = _statement.execute(); 68 if (!result) 69 { 70 _result += _statement.getUpdateCount(); 71 } 72 _index = 0; 73 } 75 76 public int executeBatch() throws SQLException 77 { 78 int result = _result; 79 clearBatch(); 80 return result; 81 } 82 83 public void clearBatch() throws SQLException 84 { 85 _index = 0; 87 _result = 0; 88 } 89 90 } 91 92 93 94 95 96 97 | Popular Tags |