Discussion Locked

Problem:Insert_ display big numeric # db

0 helpful
6 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hi,
Please help. How do I insert and display a large numeric(24,6) - 18 digits to the left of decimal and six digits to the right of decimal? I used double data type to insert and display the value to and from the db2/400. Only 16 digits from the left of decimal is accurate and the rest is incorrect. For example:
the inserting value-123456789012345678.123456;
the value in db is-123,456,789,012,345,680.000000;
displaying the value is-1.2345678901234568E17.

Thank you,
Nhan Nguyen

6 replies

by sandesh

One way is by writing a small java program.
With JDBC, java can insert/retrieve such values as java.math.BigInteger.

The code would be something like :

...
PreparedStatement ps = con.prepareStatement("insert into TBLNAME values (?, ?, ..)");
ps.setBigInteger(1, 32546554654456);
...
ps.executeCommand();
...

Similarly for retrieval, using the "select SOMETHING from SOMETABLE where ...", the result set may be read as follows :

rs.getBigDecimal("SOMETHING");

Hope this helps.Sandesh

by nhanaiu99

Thank you for your answer.
The problem I have is the decimal number. It's not an Integer number. Beside I had used the BigDecimal but didn't help. I had isolated the problem by inserting and selecting the values from SQL and it works fine. But when using java the number changed in the java.

by nhanaiu99

Thank you for your answer but my question is regarding to the decimal number - there are 18 digits to the left of decimal point and 6 digits to the right of decimal point. I had tested the BigDecimal but it didn't work out either. I had isolated the problem to just java. When java read and write it shink the number as the example above.

by nise_k

Hi Nhan,

I think you must do some R&D on BigDecimal (you did some but I suggest more).
Best bet is creating a BigDecimal Object like this :

java.math.BigDecimal bd = new java.math.BigDecimal(data).setScale(6,java.math.BigDecimal.ROUND_HALF_EVEN);

Scale should be set as per your need.

We had faced a similar problem, and the solution was this itself.

Hope it helps.

Bye
Nise

This discussion is closed to new replies.