• Post Reply Bookmark Topic Watch Topic
  • New Topic

Handling null numeric values in a result set

Bill Hamlin
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!

Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!