aspose file tools*
The moose likes JDBC and the fly likes BigDecimal value from a Double Value ERROR Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "BigDecimal value from a Double Value ERROR" Watch "BigDecimal value from a Double Value ERROR" New topic
Author

BigDecimal value from a Double Value ERROR

steve hoover
Greenhorn

Joined: Feb 07, 2003
Posts: 2
Hello.
I am using Jbuilder 6.
We recently upgraged our Oracle Database from 9.2.0.1.0 to 9.2.0.3.0.
Ever since the upgrade I have been unable to select a sequence value from my database within my java application.
Here is the line of code that is failing: dataSet.setBigDecimal(primaryKeyName,sequenceGeneratorQueryDataSet.getBigDecimal("SEQ_NUM"));
I get the following error:
Attempt to get a BIGDECIMAL value from a DOUBLE value.
The only changes that have occured in the databse was the previously mentioned database upgrade.
Has anyone else had this problem?
I have been looking at the patchsets' readme file but have not found what could have caused the problem.
Any Ideas anyone?
steve hoover
Greenhorn

Joined: Feb 07, 2003
Posts: 2
For those that are interested.
I logged a TAR with Oracle and found out the following:
This is from Oracle:
Starting on JDBC 9.0.1.4 there has been a change of behaviour on the datatype returned from getMetaData() in jdbc.
If Oracle returns a NUMBER datatype to JDBC. The results of the datatype type output are different in 9.0.1.3 than in 9.2.0.2.
This change of behaviour is experienced using JDBC THIN or OCI and independent to what version of the database they connect to.
.
In 8i and 9.0.1.3, A number datatype was mapped to: java type of: java.math.BigDecimal
=============================
in 9014, 9202 and 10i, A number datatype is mapped to : java.lang.Integer
============================
According to java, sql datatype mappings table documented on the JDBC developers guide and reference:
Table 20-1 Valid SQL Datatype-Java Class Mappings .
(http://st-doc.us.oracle.com/9.0/9202/java.920/a96654/ref.htm#1000969)
.
See 3.0 JDBC spec, http://java.sun.com/products/jdbc/download.html.
From the JDBC spec 3.0 API Table B3 " Mapping from JDBC types to Java Object Types"
.
JDBC type Java Object type
------------------------------------------
INTEGER Integer
In this case we are register the JDBC type to be of type java.sql.Integer, by using registerOutParameter(1, java.sql.Types.INTEGER).
So, the 9014, 92 is the correct behavior.
The old behavior (8i to 9013) was violating the jdbc 3.0 spec and the new behvior is the correct one as required by J2EE CTS (JAVA Certification Suite for J2EE complient), for that reason Oracle integrated a set of changes on their 9.0.1.4 version of the driver and above.
Please note that JDBC 9013 can still be used with 920X database. As this configuration was done for our iAS product.
As a result I had to remove the following call:
dataSet.setBigDecimal(primaryKeyName,sequenceGeneratorQueryDataSet.getBigDecimal("SEQ_NUM"));
and replace it with :
Statement stmt;
Connection conn = sTEPDataModule.getDatabase().getJdbcConnection();
stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery( "select "+sequenceGeneratorName+".nextval SEQ_NUM from dual");
rs.next();
dataSet.setBigDecimal(primaryKeyName,rs.getBigDecimal(1));
This seems to work with no problems.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: BigDecimal value from a Double Value ERROR