• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

null value for int

 
Pavan Kumar
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if to send a null value while binding the variables to callble statement.
suppose in following statement contractseq is int. Then how to send this value as null.We can use setNull method to set it as null. But I need to initialse contractseq as null, how to do this? INTEGER can set to null,but how to set int as null.
csorder.setInt(20,p_contractseq);
regards
Pavan
 
Wayne L Johnson
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since a Java "int" can't ever be null you have a couple of choices. Either you make a convention that a null will be represented by an unlikely value (such as Integer.MIN_VALUE), or you use an "Integer" instead.
In the first case, if you want to set an "int" to null, you set contractseq = Integer.MIN_VALUE. Inside the receiving method you check for a value of "Integer.MIN_VALUE" and if found do a "setNull()", otherwise do a "setInt()". This works, but it is sorta' ugly, and would prevent you from ever storing Integer.MIN_VALUE in the database.
The second option means you have to wrap/unwrap the "int" value, but allows you to pass a null around.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic