Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ResultSet.getInt return wrong value.

 
Swapneel Killekar
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My SQL Query returns 1800.0000 when i view it from Toad.

By when i do ResultSet.getInt("columnname") it return 1799 instead of 1800.

Can any one please tell me why this value gets changed in JDBC

Thanks in advance

regards
Swapneel Killekar.
 
Philip Grove
Ranch Hand
Posts: 68
Firefox Browser Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would suspect a problem in Toad, probably configuration, since it is viewed as 1800.0000, as int is an integer type and as such does not contain any decimals.

Do you know, or have any way to find out, what is the correct value of the field? Because there are several suspects and before trouble shooting we need to figure out who is right.
 
Swapneel Killekar
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its a computed value and in oracle i shall be Decimal.
thou i got the proper value by using (int)ResultSet.getDouble("columnname")

i just wanted to know how come one is getting subtracted when i do a getInt() on a decimal field.
 
Philip Grove
Ranch Hand
Posts: 68
Firefox Browser Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1 is not getting subtracted when you do a getInt on a decimal field, but mapping can yield unexpected results.

Knowing what the field contains and the field type are the first steps towards figuring out what is happening.

Let me see if I got this right:
ResultSet.getInt("columnname") return 1799
(int)ResultSet.getDouble("columnname") returns 1800

Do not rely on a typecast to fix your problem (explicit typecasts should be avoided when possible) but return the decimal value to your code and deal with it properly, java.lang.Math might help your along your way.
 
Swapneel Killekar
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Philip

I am now using Math class. But we could say its a undefined operation on getInt()
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic