wood burning stoves 2.0*
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 Murach's Java Servlets and JSP this week in the Servlets 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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Strange Number Problem
 
Similar Threads
Problem in inserting from one table to another
I'm new to jdbc,please help me with this code!
Returning a table into an array.
Paging in jsp
isNew() method