wood burning stoves 2.0*
The moose likes JDBC and the fly likes null value for int Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "null value for int" Watch "null value for int" New topic
Author

null value for int

Pavan Kumar
Greenhorn

Joined: Jan 13, 2002
Posts: 8
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


pavan kuamr
Wayne L Johnson
Ranch Hand

Joined: Sep 03, 2003
Posts: 399
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.
 
Consider Paul's rocket mass heater.
 
subject: null value for int