My Oracle Support Banner

Value from Column in the Database Is Not Displayed With Exact Same Scale as Sql*Plus When Using JDBC (Doc ID 1362964.1)

Last updated on JULY 29, 2019

Applies to:

JDBC - Version 10.1.0.5 to 11.2.0.2.0 [Release 10.1 to 11.2]
Information in this document applies to any platform.

Symptoms

The value from the database column is not displayed with the exact same scale when using a Java program with JDBC.

For example:

SQL> create table test(id number(3,2));

Table created

SQL> insert into test values(1.20);

SQL> commit;

SQL> col id for 9.99
SQL> select id from test;

ID
-----
1.20



This gives the correct result , but it is not the same if  JDBC Thin driver is used in below code:


stmt = conn.prepareStatement("select id1 from test9");

ResultSet result = stmt.executeQuery();
while (result.next()) {
System.out.print(result.getBigDecimal(1) + "\t");
System.out.println();
}


The result from this java program is:


1.2

Modifying the code to use String instead of  BigDecimal also fails to display the same scale as in SQL*Plus:

stmt = conn.prepareStatement("select id1 from test9");

ResultSet result = stmt.executeQuery();
while (result.next()) {
System.out.print(result.getString(1) + "\t"); //***change to getSting from getBIgDecimal
System.out.print(result.getString(2)+"\t");
System.out.println();
}



The result from the java program is again:

1.2

Cause

To view full details, sign in with your My Oracle Support account.

Don't have a My Oracle Support account? Click to get started!


In this Document
Symptoms
Cause
Solution


My Oracle Support provides customers with access to over a million knowledge articles and a vibrant support community of peers and Oracle experts.