开发者

Uses of PreparedStatement setNull

开发者 https://www.devze.com 2023-03-02 11:39 出处:网络
What is the uses of s开发者_C百科etNull() method in PreparedStatement interface? I looked in this post.

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 ).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号