• Post Reply Bookmark Topic Watch Topic
  • New Topic

handle null value from database  RSS feed

 
senthil karun
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a below code
int id = rs.getInt("regID")

the regID column got null values in it, I want to assign 0 if the value is null, i tried
if(rs.getInt("regID ") == null){
regID=0;
}
nut it gave me below error
incomparable types: int and <nulltype>

Please anyone advice me how to handle null values from database in java.

Thanks
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ResultSet has a method called wasNull - check that out. Also, getInt already returns 0 if the database value is null, so just calling "int id = rs.getInt("regID")" will do what you want.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!