Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Double value 'infinity' causes IllegalArgumentException

2888967Feb 22 2015 — edited Feb 24 2015

Trying to bind the value Double.POSITIVE_INFINITY in a prepared statement causes an IllegalArgumentException using ojdbc6 11.2.0.4.0 but it works fine in version 11.2.0.3.0:

Exception in thread "main" java.lang.IllegalArgumentException: Overflow

    at oracle.jdbc.driver.OraclePreparedStatement.setDoubleInternal(OraclePreparedStatement.java:7605)

    at oracle.jdbc.driver.OraclePreparedStatement.setDouble(OraclePreparedStatement.java:7513)

    at oracle.jdbc.driver.OraclePreparedStatementWrapper.setDouble(OraclePreparedStatementWrapper.java:494)

    at DoubleOverflow.main(DoubleOverflow.java:26)

Source:

import java.sql.*;

import oracle.jdbc.pool.OracleDataSource;

public class DoubleOverflow

{

  public static void main (String[] args) throws SQLException {

    OracleDataSource ods = new OracleDataSource();

    ods.setUser(System.getProperty("DB_USER"));

    ods.setPassword(System.getProperty("DB_PASSWORD"));

    ods.setURL(System.getProperty("JDBC_URL"));

    Connection conn = ods.getConnection();

    PreparedStatement pstmtCreateTable = conn.prepareStatement("create table ojdbc6test (d BINARY_DOUBLE)");

    try {

        pstmtCreateTable.execute();

    } catch (Exception ex) {

        if (ex.getMessage().contains("ORA-00955")) {

            System.err.println("Test table already created - ignore SQL error and continue");

        } else throw ex;

    }

    pstmtCreateTable.close();

    PreparedStatement pstmt = conn.prepareStatement ("insert into ojdbc6test (d) VALUES (?)");

    // This will cause an IllegalArgumentException in ojdbc6 11.2.0.4.0 but not in 11.2.0.3.0

    pstmt.setDouble(1, Double.POSITIVE_INFINITY);

    pstmt.execute ();

    pstmt.close();

    conn.close();

  }

}

The database used is 'Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production'. I don't see any mention regarding changes to this in the 11.2.0.4.0 change log. Is this a bug in the driver or is there some other explanation?

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 24 2015
Added on Feb 22 2015
5 comments
4,940 views