What is the uses of s开发者_C百科etNull() method in PreparedStatement interface? I looked in this post.
It says: Without the setNull(..) method there would be no way to set null values for the Java primitives.
however with autoboxing in JDK5, I think null values can be set on even primitive types.
There is another post in some other forum says:If you want to be portable to different databases, use the setNull() method.
However there is nothing clearly mentioned in Java doc. Could you help me understanding this?
I think it's easier to understand this if you view it from the database end. If you want to set a field to NULL in your database insert statement, then you need a way of telling the database that is should be set to NULL rather than the default value for the column. If in the database schema you have a nullable integer field, you would use set null to set it to the DB NULL value, rather than to its default value ( 0 ).
精彩评论