oracle.jdbc.OraclePreparedStatement Java Examples

The following examples show how to use oracle.jdbc.OraclePreparedStatement. 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: OracleClient.java    From presto with Apache License 2.0 4 votes vote down vote up
public static LongWriteFunction oracleRealWriteFunction()
{
    return (statement, index, value) -> ((OraclePreparedStatement) statement).setBinaryFloat(index, intBitsToFloat(toIntExact(value)));
}
 
Example #2
Source File: OracleClient.java    From presto with Apache License 2.0 4 votes vote down vote up
public static DoubleWriteFunction oracleDoubleWriteFunction()
{
    return ((statement, index, value) -> ((OraclePreparedStatement) statement).setBinaryDouble(index, value));
}
 
Example #3
Source File: StatementAdaptor.java    From database with Apache License 2.0 4 votes vote down vote up
public void addParameters(PreparedStatement ps, Object[] parameters) throws SQLException {
  for (int i = 0; i < parameters.length; i++) {
    Object parameter = parameters[i];

    // Unwrap secret args here so we can use them
    if (parameter instanceof SecretArg) {
      parameter = ((SecretArg) parameter).getArg();
    }

    if (parameter == null) {
      ParameterMetaData metaData;
      int parameterType;
      try {
        metaData = ps.getParameterMetaData();
        parameterType = metaData.getParameterType(i + 1);
      } catch (SQLException e) {
        throw new DatabaseException("Parameter " + (i + 1)
            + " was null and the JDBC driver could not report the type of this column."
            + " Please update the JDBC driver to support PreparedStatement.getParameterMetaData()"
            + " or use SqlNull in place of null values to this query.", e);
      }
      ps.setNull(i + 1, parameterType);
    } else if (parameter instanceof SqlNull) {
      SqlNull sqlNull = (SqlNull) parameter;
      if (options.useBytesForBlob() && sqlNull.getType() == Types.BLOB) {
        // The setNull() seems more correct, but PostgreSQL chokes on it
        ps.setBytes(i + 1, null);
      } else {
        ps.setNull(i + 1, sqlNull.getType());
      }
    } else if (parameter instanceof java.sql.Date) {
      ps.setDate( i + 1, (java.sql.Date) parameter);
    } else if (parameter instanceof Date) {
      // this will correct the millis and nanos according to the JDBC spec
      // if a correct Timestamp is passed in, this will detect that and leave it alone
      ps.setTimestamp(i + 1, toSqlTimestamp((Date) parameter), options.calendarForTimestamps());
    } else if (parameter instanceof Reader) {
      if (options.useStringForClob()) {
        ps.setString(i + 1, readerToString((Reader) parameter));
      } else {
        ps.setCharacterStream(i + 1, (Reader) parameter);
      }
    } else if (parameter instanceof InputStream) {
      if (options.useBytesForBlob()) {
        ps.setBytes(i + 1, streamToBytes((InputStream) parameter));
      } else {
        ps.setBinaryStream(i + 1, (InputStream) parameter);
      }
    } else if (parameter instanceof Float) {
      if (options.flavor() == Flavor.oracle && ps.isWrapperFor(OraclePreparedStatement.class)) {
        // The Oracle 11 driver setDouble() first converts the double to NUMBER, causing underflow
        // for small values so we need to use the proprietary mechanism
        ps.unwrap(OraclePreparedStatement.class).setBinaryFloat(i + 1, (Float) parameter);
      } else {
        ps.setFloat(i + 1, (Float) parameter);
      }
    } else if (parameter instanceof Double) {
      if (options.flavor() == Flavor.oracle && ps.isWrapperFor(OraclePreparedStatement.class)) {
        // The Oracle 11 driver setDouble() first converts the double to NUMBER, causing underflow
        // for small values so we need to use the proprietary mechanism
        ps.unwrap(OraclePreparedStatement.class).setBinaryDouble(i + 1, (Double) parameter);
      } else {
        ps.setDouble(i + 1, (Double) parameter);
      }
    } else {
      ps.setObject(i + 1, parameter);
    }
  }
}