Java Code Examples for java.sql.PreparedStatement#setRef()
The following examples show how to use
java.sql.PreparedStatement#setRef() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PreparedStatementWrapper.java From Oceanus with Apache License 2.0 | 5 votes |
@Override public void setRef(final int parameterIndex, final Ref x) throws SQLException { ParameterCallback callback = new ParameterCallbackAction( parameterIndex, x) { @Override public void call(PreparedStatement preparedStatement) throws SQLException { preparedStatement.setRef(parameterIndex(), x); } }; addParameterCallback(callback); }
Example 2
Source File: RefPreparedStatementIndexSetter.java From SimpleFlatMapper with MIT License | 5 votes |
@Override public void set(PreparedStatement target, Ref value, int columnIndex, Context context) throws SQLException { if (value == null) { target.setNull(columnIndex, Types.REF); } else { target.setRef(columnIndex, value); } }
Example 3
Source File: UnsupportedOperationPreparedStatementTest.java From sharding-jdbc-1.5.1 with Apache License 2.0 | 4 votes |
@Test(expected = SQLFeatureNotSupportedException.class) public void assertSetRef() throws SQLException { for (PreparedStatement each : statements) { each.setRef(1, null); } }
Example 4
Source File: ResultSetEnumerable.java From Quicksql with MIT License | 4 votes |
/** Assigns a value to a dynamic parameter in a prepared statement, calling * the appropriate {@code setXxx} method based on the type of the value. */ private static void setDynamicParam(PreparedStatement preparedStatement, int i, Object value) throws SQLException { if (value == null) { preparedStatement.setObject(i, null, SqlType.ANY.id); } else if (value instanceof Timestamp) { preparedStatement.setTimestamp(i, (Timestamp) value); } else if (value instanceof Time) { preparedStatement.setTime(i, (Time) value); } else if (value instanceof String) { preparedStatement.setString(i, (String) value); } else if (value instanceof Integer) { preparedStatement.setInt(i, (Integer) value); } else if (value instanceof Double) { preparedStatement.setDouble(i, (Double) value); } else if (value instanceof java.sql.Array) { preparedStatement.setArray(i, (java.sql.Array) value); } else if (value instanceof BigDecimal) { preparedStatement.setBigDecimal(i, (BigDecimal) value); } else if (value instanceof Boolean) { preparedStatement.setBoolean(i, (Boolean) value); } else if (value instanceof Blob) { preparedStatement.setBlob(i, (Blob) value); } else if (value instanceof Byte) { preparedStatement.setByte(i, (Byte) value); } else if (value instanceof NClob) { preparedStatement.setNClob(i, (NClob) value); } else if (value instanceof Clob) { preparedStatement.setClob(i, (Clob) value); } else if (value instanceof byte[]) { preparedStatement.setBytes(i, (byte[]) value); } else if (value instanceof Date) { preparedStatement.setDate(i, (Date) value); } else if (value instanceof Float) { preparedStatement.setFloat(i, (Float) value); } else if (value instanceof Long) { preparedStatement.setLong(i, (Long) value); } else if (value instanceof Ref) { preparedStatement.setRef(i, (Ref) value); } else if (value instanceof RowId) { preparedStatement.setRowId(i, (RowId) value); } else if (value instanceof Short) { preparedStatement.setShort(i, (Short) value); } else if (value instanceof URL) { preparedStatement.setURL(i, (URL) value); } else if (value instanceof SQLXML) { preparedStatement.setSQLXML(i, (SQLXML) value); } else { preparedStatement.setObject(i, value); } }
Example 5
Source File: RefGetterMapping.java From butterfly-persistence with Apache License 2.0 | 4 votes |
protected void insertObjectDo(Object value, PreparedStatement statement, int index) throws SQLException { statement.setRef(index, (Ref) value); }
Example 6
Source File: RefParamContext.java From Zebra with Apache License 2.0 | 4 votes |
@Override public void setParam(PreparedStatement stmt) throws SQLException { stmt.setRef(index, (Ref) values[0]); }
Example 7
Source File: UnsupportedOperationPreparedStatementTest.java From shardingsphere with Apache License 2.0 | 4 votes |
@Test(expected = SQLFeatureNotSupportedException.class) public void assertSetRef() throws SQLException { for (PreparedStatement each : statements) { each.setRef(1, null); } }
Example 8
Source File: DatabaseUtils.java From StatsAgg with Apache License 2.0 | 4 votes |
private static int setPreparedStatementParameter(PreparedStatement preparedStatement, List<Object> preparedStatementParameters, Object object, AtomicInteger index) { if ((preparedStatement == null) || (preparedStatementParameters == null)) { logger.warn("Can't set preparedStatementParameters - preparedStatementParameters or preparedStatement is null"); return -1; } try { if (object == null) { preparedStatement.setObject(index.getAndIncrement(), null); } else if (object instanceof BigDecimal) { preparedStatement.setBigDecimal(index.getAndIncrement(), (BigDecimal) object); } else if (object instanceof Blob) { preparedStatement.setBlob(index.getAndIncrement(), (Blob) object); } else if (object instanceof Boolean) { preparedStatement.setBoolean(index.getAndIncrement(), (Boolean) object); } else if (object instanceof Byte) { preparedStatement.setByte(index.getAndIncrement(), (Byte) object); } else if (object instanceof byte[]) { preparedStatement.setBytes(index.getAndIncrement(), (byte[]) object); } else if (object instanceof Clob) { preparedStatement.setClob(index.getAndIncrement(), (Clob) object); } else if (object instanceof Double) { preparedStatement.setDouble(index.getAndIncrement(), (Double) object); } else if (object instanceof Float) { preparedStatement.setFloat(index.getAndIncrement(), (Float) object); } else if (object instanceof Integer) { preparedStatement.setInt(index.getAndIncrement(), (Integer) object); } else if (object instanceof List) { for (Object listObject : (List) object) { setPreparedStatementParameter(preparedStatement, preparedStatementParameters, listObject, index); } } else if (object instanceof Long) { preparedStatement.setLong(index.getAndIncrement(), (Long) object); } else if (object instanceof NClob) { preparedStatement.setNClob(index.getAndIncrement(), (NClob) object); } else if (object instanceof Ref) { preparedStatement.setRef(index.getAndIncrement(), (Ref) object); } else if (object instanceof RowId) { preparedStatement.setRowId(index.getAndIncrement(), (RowId) object); } else if (object instanceof SQLXML) { preparedStatement.setSQLXML(index.getAndIncrement(), (SQLXML) object); } else if (object instanceof Short) { preparedStatement.setShort(index.getAndIncrement(), (Short) object); } else if (object instanceof String) { preparedStatement.setString(index.getAndIncrement(), (String) object); } else if (object instanceof Time) { preparedStatement.setTime(index.getAndIncrement(), (Time) object); } else if (object instanceof java.sql.Timestamp) { preparedStatement.setTimestamp(index.getAndIncrement(), (java.sql.Timestamp) object); } else if (object instanceof java.sql.Date) { preparedStatement.setDate(index.getAndIncrement(), (java.sql.Date) object); } else if (object instanceof java.util.Date) { java.util.Date tempDate = (java.util.Date) object; java.sql.Date dateSql = new java.sql.Date(tempDate.getTime()); preparedStatement.setDate(index.getAndIncrement(), dateSql); } else { if (object instanceof Object) {} else { logger.warn("Setting PreparedStatement parameter to 'object' type when object is not an object type"); } preparedStatement.setObject(index.getAndIncrement(), object); } return index.get(); } catch (Exception e) { logger.error(e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e)); return -1; } }
Example 9
Source File: ResultSetEnumerable.java From calcite with Apache License 2.0 | 4 votes |
/** Assigns a value to a dynamic parameter in a prepared statement, calling * the appropriate {@code setXxx} method based on the type of the value. */ private static void setDynamicParam(PreparedStatement preparedStatement, int i, Object value) throws SQLException { if (value == null) { preparedStatement.setObject(i, null, SqlType.ANY.id); } else if (value instanceof Timestamp) { preparedStatement.setTimestamp(i, (Timestamp) value); } else if (value instanceof Time) { preparedStatement.setTime(i, (Time) value); } else if (value instanceof String) { preparedStatement.setString(i, (String) value); } else if (value instanceof Integer) { preparedStatement.setInt(i, (Integer) value); } else if (value instanceof Double) { preparedStatement.setDouble(i, (Double) value); } else if (value instanceof java.sql.Array) { preparedStatement.setArray(i, (java.sql.Array) value); } else if (value instanceof BigDecimal) { preparedStatement.setBigDecimal(i, (BigDecimal) value); } else if (value instanceof Boolean) { preparedStatement.setBoolean(i, (Boolean) value); } else if (value instanceof Blob) { preparedStatement.setBlob(i, (Blob) value); } else if (value instanceof Byte) { preparedStatement.setByte(i, (Byte) value); } else if (value instanceof NClob) { preparedStatement.setNClob(i, (NClob) value); } else if (value instanceof Clob) { preparedStatement.setClob(i, (Clob) value); } else if (value instanceof byte[]) { preparedStatement.setBytes(i, (byte[]) value); } else if (value instanceof Date) { preparedStatement.setDate(i, (Date) value); } else if (value instanceof Float) { preparedStatement.setFloat(i, (Float) value); } else if (value instanceof Long) { preparedStatement.setLong(i, (Long) value); } else if (value instanceof Ref) { preparedStatement.setRef(i, (Ref) value); } else if (value instanceof RowId) { preparedStatement.setRowId(i, (RowId) value); } else if (value instanceof Short) { preparedStatement.setShort(i, (Short) value); } else if (value instanceof URL) { preparedStatement.setURL(i, (URL) value); } else if (value instanceof SQLXML) { preparedStatement.setSQLXML(i, (SQLXML) value); } else { preparedStatement.setObject(i, value); } }