• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Handle Null Values

 
Mark Reyes
Ranch Hand
Posts: 426
  • 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
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • 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
  • 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?

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic