• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Retrieving BigDecimal value from Netezza DB using JDBC

 
subhasri paulmony
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am trying to retrieve a BigDecimal value from Netezza database using jdbc, in my machine it works
in another machine it displays only the digits before the decimal point

for ex : 1.08765678 is a BigDecimal value from DB

and I do

value=rs.getBigDecimal("column_name");

I am getting 1.08765678 ( my machine has JDK_VERSION = 1.7.0_40)

but in another machine it is displaying as 1 ( the other machine has Java Version: 1.6.0_45)

please help

I also tried rs.getBigDecimal("column_name").setScale(7)

 
Campbell Ritchie
Sheriff
Posts: 51453
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

You appear to have landed in the wrong forum; I shall move you to our database forum.
Don't know. Sorry. You do realise that JDK1.7.0_40 is out of date; use this.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

Your Java code to get the BigDecimal is correct. Can you show how you are printing out the BigDecimal?
 
subhasri paulmony
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am getting like this

BigDecimal adjustmentFactor;
StringBuffer sb = new StringBuffer(512);

adjustmentFactor=rs.getBigDecimal("ADJUSTMENT_FACTOR")
sb.append(String.format("%-9s",String.valueOf(adjustmentFactor)));
 
Paul Clapham
Sheriff
Posts: 21583
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems like something changed between Java 6 and Java 7. However you have a bunch of things going on there -- database access and string formatting at least -- which makes it hard to pinpoint the problem.

So try taking out the database access; replace that code by something which just assigns a hard-coded BigDecimal value and formats it, and see if the problem persists.
 
subhasri paulmony
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the problem is even before formatting

I ran the application in debug mode and in the below line

adjustmentFactor=rs.getBigDecimal("ADJUSTMENT_FACTOR")

when I check the value of adjustmentFactor after the assignment (in debug mode), only value "1" is stored in it. but the actual value from the database is 1.08765678
 
Paul Clapham
Sheriff
Posts: 21583
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then you have isolated the problem. That's a good first step. Now, you said that one version of the code used Java 6 and the other used Java 7. That's a possible source of differences but there could be others. A more relevant question would be, are they using the same version of the JDBC driver?
 
subhasri paulmony
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this seems to be an issue with the nzjdbc.jar (Release 4.6.5 driver [build 10670])


I tried with the most recent version of the jar (NPS 7.02 P11) and it is working now

thank you very much for your earlier responses
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic