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 Strange Number Problem 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 "Strange Number Problem" Watch "Strange Number Problem" New topic
Author

Strange Number Problem

Darren Jackson
Ranch Hand

Joined: Jan 18, 2007
Posts: 42
Below is some code I am using to count the number of rows in a database whos magnitude levels are either above or below an estimate value.

All the values in my database are below 6.

This works fine unitl I set the integer estimate to be 10 or above.

When I set it to 10 or above I get the reply of 7 above and 3 below.

I do have 3 values that are between 1 and 1.9 though.

Can anyone see any reason why this could be?

All the queries run fine if I run them on the database themselves.

Could it be to do with the way Java creates the number 10 or above?



[ January 22, 2007: Message edited by: Darren Jackson ]
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Your query looks like this, right?
SELECT COUNT(Magnitude) FROM Objects WHERE Magnitude < "10" ORDER BY Magnitude ASC
Then you're doing a text comparison, not a numeric comparison. In a text comparison, "10" comes alphabetically before "6". Drop the quotes if you want a numeric comparison.
Darren Jackson
Ranch Hand

Joined: Jan 18, 2007
Posts: 42
Thank you for your reply.

It turns out that the problem was the way the SQL database was set up.

Cheers.

Darren
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Strange Number Problem