Share via


Breaking change in JVM 1.5 API for Big Decimal class

   If you are porting your JDBC application for SQL Server from 1.4 JVM to 1.5 JVM you might run into problems caused by the breaking change in the toString method of Big Decimal class. Namely, the following code prints out different values across different JVM versions.

String str = new BigDecimal("1E10").toString();

System.out.println("String is " + str);

//With 1.4 prints 'String is 10000000000'

//With 1.5 prints 'String is 1E+10

 

Neither SQL Server 2000 nor SQL Server 2005 converts string representations of numeric values that contain the exponential into numeric types. Accordingly, the following code would succeed when executed against 1.4 while failing against 1.5.

 

ResultSet rs = stmt.executeQuery("Select * from temp");

rs.next();

rs.updateString("col1", str);

rs.updateRow();

 

Exception thrown against 1.5 would be like the following:

 

com.microsoft.sqlserver.jdbc.SQLServerException:Error converting data type nvarchar to numeric.

The work around for this issue is simple. 1.5 API introduces a new BigDecimal method, toPlainString that is guaranteed to exhibit the same behavior as the toString method in 1.4. You can find more information about this change in 1.5 in Sun's bug database.

https://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6298816