List of usage examples for java.sql PreparedStatement setObject
default void setObject(int parameterIndex, Object x, SQLType targetSqlType) throws SQLException
From source file:org.thingsboard.server.service.install.sql.SqlDbHelper.java
private static void setColumnValue(int index, String column, CSVRecord record, PreparedStatement preparedStatement) throws SQLException { String value = record.get(column); int type = preparedStatement.getParameterMetaData().getParameterType(index + 1); preparedStatement.setObject(index + 1, value, type); }
From source file:org.quartz.impl.jdbcjobstore.DB2v7Delegate.java
/** * Sets the designated parameter to the byte array of the given * <code>ByteArrayOutputStream</code>. Will set parameter value to null if the * <code>ByteArrayOutputStream</code> is null. * Wraps <code>{@link PreparedStatement#setObject(int, java.lang.Object, int)}</code> rather than * <code>{@link PreparedStatement#setBytes(int, byte[])}</code> as required by the * DB2 v7 database./*from w w w. ja v a 2 s. c o m*/ */ protected void setBytes(PreparedStatement ps, int index, ByteArrayOutputStream baos) throws SQLException { ps.setObject(index, ((baos == null) ? null : baos.toByteArray()), java.sql.Types.BLOB); }
From source file:org.gbif.drupal.mybatis.EnumDictTypeHandler.java
@Override public void setParameter(PreparedStatement ps, int i, T parameter, JdbcType jdbcType) throws SQLException { ps.setObject(i, parameter == null ? null : parameter.name(), Types.CHAR); }
From source file:com.wabacus.system.datatype.ShortType.java
public void setPreparedStatementValue(int iindex, String value, PreparedStatement pstmt, AbsDatabaseType dbtype) throws SQLException { log.debug("setShort(" + iindex + "," + value + ")"); Object objTmp = label2value(value); if (objTmp == null) { pstmt.setObject(iindex, null, java.sql.Types.SMALLINT); } else {//w w w . j av a 2 s . co m pstmt.setShort(iindex, (Short) objTmp); } }
From source file:com.tomoare.mybatis.type.EnumValueTypeHandler.java
@Override public void setNonNullParameter(PreparedStatement ps, int i, E parameter, JdbcType jdbcType) throws SQLException { if (jdbcType == null) { ps.setString(i, ((DbCodeConstant) parameter).getCodeValue()); } else {/*w w w . j a va 2 s. c o m*/ ps.setObject(i, ((DbCodeConstant) parameter).getCodeValue(), jdbcType.TYPE_CODE); // TODO } }
From source file:com.wabacus.system.datatype.DoubleType.java
public void setPreparedStatementValue(int iindex, String value, PreparedStatement pstmt, AbsDatabaseType dbtype) throws SQLException { log.debug("setDouble(" + iindex + "," + value + ")"); Object objTmp = label2value(value); if (objTmp == null) { pstmt.setObject(iindex, null, java.sql.Types.DOUBLE); } else {/*from w ww . ja v a 2s . c o m*/ pstmt.setDouble(iindex, (Double) objTmp); } }
From source file:com.wabacus.system.datatype.FloatType.java
public void setPreparedStatementValue(int iindex, String value, PreparedStatement pstmt, AbsDatabaseType dbtype) throws SQLException { log.debug("setFloat(" + iindex + "," + value + ")"); Object objTmp = label2value(value); if (objTmp == null) { pstmt.setObject(iindex, null, java.sql.Types.FLOAT); } else {//from w w w .j av a 2s . c o m pstmt.setFloat(iindex, (Float) objTmp); } }
From source file:com.wabacus.system.datatype.IntType.java
public void setPreparedStatementValue(int iindex, String value, PreparedStatement pstmt, AbsDatabaseType dbtype) throws SQLException { log.debug("setInt(" + iindex + "," + value + ")"); Object objTmp = label2value(value); if (objTmp == null) { pstmt.setObject(iindex, null, java.sql.Types.INTEGER); } else {//w w w . j ava 2 s . co m pstmt.setInt(iindex, (Integer) objTmp); } }
From source file:com.wabacus.system.datatype.LongType.java
public void setPreparedStatementValue(int iindex, String value, PreparedStatement pstmt, AbsDatabaseType dbtype) throws SQLException { log.debug("setLong(" + iindex + "," + value + ")"); Object objTmp = label2value(value); if (objTmp == null) { pstmt.setObject(iindex, null, java.sql.Types.BIGINT); } else {// w ww. j ava2s .c o m pstmt.setLong(iindex, (Long) objTmp); } }
From source file:com.mtgi.analytics.sql.BehaviorTrackingDataSourceTest.java
@Test public void testPreparedStatement() throws Exception { //test tracking through the prepared statement API, which should also //log parameters in the events. PreparedStatement stmt = conn.prepareStatement("insert into TEST_TRACKING values (?, ?, ?)"); stmt.setLong(1, 1);/*from w w w .j av a2 s.co m*/ stmt.setString(2, "hello"); stmt.setObject(3, null, Types.VARCHAR); assertEquals(1, stmt.executeUpdate()); //test support for batching. each batch should log 1 event. stmt.setLong(1, 3); stmt.setString(2, "batch"); stmt.setObject(3, "1", Types.VARCHAR); stmt.addBatch(); stmt.setLong(1, 4); stmt.setString(2, "batch"); stmt.setObject(3, "2", Types.VARCHAR); stmt.addBatch(); stmt.executeBatch(); //back to a regular old update. stmt.setLong(1, 2); stmt.setObject(2, "goodbye", Types.VARCHAR); stmt.setNull(3, Types.VARCHAR); assertEquals(1, stmt.executeUpdate()); stmt = conn.prepareStatement("update TEST_TRACKING set DESCRIPTION = 'world'"); assertEquals(4, stmt.executeUpdate()); stmt = conn.prepareStatement("select ID from TEST_TRACKING order by ID"); ResultSet rs = stmt.executeQuery(); int index = 0; long[] keys = { 1L, 2L, 3L, 4L }; while (rs.next()) assertEquals(keys[index++], rs.getLong(1)); rs.close(); assertEquals(4, index); manager.flush(); assertEventDataMatches("BehaviorTrackingDataSourceTest.testPreparedStatement-result.xml"); }