jQuery in Action, 2nd edition*
The moose likes JDBC and the fly likes Handling null numeric values in a result set 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 "Handling null numeric values in a result set" Watch "Handling null numeric values in a result set" New topic

Handling null numeric values in a result set

Bill Hamlin

Joined: Jun 20, 2008
Posts: 1
I'm trying to write a generic object factory class that I can run against a database table and produce an object with a constructor, getters, setters and methods to test if values have changes and to save changes to the table.

I've always been a little weak on how to handle numeric values, since the jdbc getters (getInt, getDouble, etc) return zero if the database value is null.

I'm aware of the wasNull test, but in order to use it I guess I'll have to create my objects using objects like Integer and Double in place of the primitives like int and double (which is what I have to use in my result set getters).

Anybody have any advice on a best practice for handling this sort of thing? I obviously don't want to be setting real values (zeros) to null fields when I do updates!

Any help or suggestions would be appreciated!

I agree. Here's the link: http://aspose.com/file-tools
subject: Handling null numeric values in a result set
Similar Threads
HibernateException - Wrong column type
Trouble with model for calculating and adding table values dependent on multiple rows
DriverManager error
[URLyBird] Should I use a business object or String[] in my Data class?
Encryption /Decryption