File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Strange Number Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Strange Number Problem" Watch "Strange Number Problem" New topic

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

Joined: Oct 14, 2005
Posts: 19973

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.


I agree. Here's the link:
subject: Strange Number Problem
It's not a secret anymore!