PreparedStatement setNull(..) [英] PreparedStatement setNull(..)

查看:277
本文介绍了PreparedStatement setNull(..)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java PreparedStatement提供了明确设置Null值的可能性。这种可能性是:

Java PreparedStatement provides a possibility to explicitely set a Null value. This possibility is:

prepStmt.setNull(parameterIndex, Types.VARCHAR);

此调用的语义是否与使用具有null参数的特定setType时的语义相同?

Are the semantics of this call the same as when using a specific setType with a null parameter?

prepStmt.setString(null);

推荐答案

这个指南说:

6.1.5将JDBC NULL作为IN参数发送

6.1.5 Sending JDBC NULL as an IN parameter

setNull方法允许程序员发送JDBC作为IN参数的数据库的NULL(一般SQL NULL)值。但是请注意,必须仍然指定参数的JDBC类型。

The setNull method allows a programmer to send a JDBC NULL (a generic SQL NULL) value to the database as an IN parameter. Note, however, that one must still specify the JDBC type of the parameter.

当Java null值传递给数据库时,JDBC NULL也将被发送到数据库。 setXXX方法(如果它将Java对象作为参数)。但是,只有指定了JDBC类型,方法setObject才能获取空值。

A JDBC NULL will also be sent to the database when a Java null value is passed to a setXXX method (if it takes Java objects as arguments). The method setObject, however, can take a null value only if the JDBC type is specified.

所以是的,它们是等价的。

So yes they're equivalent.

这篇关于PreparedStatement setNull(..)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆