This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes JDBC and the fly likes ResultSet.getInt return wrong value. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "ResultSet.getInt return wrong value." Watch "ResultSet.getInt return wrong value." New topic
Author

ResultSet.getInt return wrong value.

Swapneel Killekar
Greenhorn

Joined: Jun 22, 2011
Posts: 14
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

Joined: Aug 18, 2009
Posts: 68

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

Joined: Jun 22, 2011
Posts: 14
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

Joined: Aug 18, 2009
Posts: 68

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

Joined: Jun 22, 2011
Posts: 14
Thanks Philip

I am now using Math class. But we could say its a undefined operation on getInt()
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ResultSet.getInt return wrong value.