This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Handle Null Values

 
Mark Reyes
Ranch Hand
Posts: 426
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a table of Date and String value. Each date column and string values represents specific logic such as unfinished transactions so each must be represented by a null value. (Not an empty string)

Now I am having a problem mapping everything in my JDBC.

Timestamp dteEndTrans = rs.getTimestamp("dteEndTrans");

if (rs.wasnull()){
//set DTO object to empty string("")
}

Is there an elegant way of handling such things rather than calling wasnull in every column?

I have another option which is in the Database Query itself wherein it will return an empty string for every null value, but I wanted the application to handle this.

Any advice please?
 
Paul Clapham
Sheriff
Pie
Posts: 20184
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're getting objects (e.g. dates and strings) then the "more elegant" way would be to just compare said objects to null directly. You only need the "wasNull" method when you're getting primitives from the database.
 
Mark Reyes
Ranch Hand
Posts: 426
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul,

Thanks for pointing that out. I thought they only work on Object type since that was I have read from the API Docs.

Going back to your suggestion.

So does it mean that for every columns, I'll have to add bunch of if statements to test if it is null?

 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic