This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes JDBC and Relational Databases 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 Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
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:
subject: Handling null numeric values in a result set
It's not a secret anymore!