PreparedStatement setnull方法中Types.INTEGER和Types.NULL之间的区别 [英] Difference between Types.INTEGER and Types.NULL in PreparedStatement setnull method
问题描述
以下语句之间有什么区别.
What is the difference between the following statements.
PreparedStatement.setNull(1, java.sql.Types.NULL);
和
PreparedStatement.setNull(1, java.sql.Types.INTEGER);
推荐答案
第一个指示驱动程序将null
值作为NULL
类型发送,而另一个则将其作为INTEGER
类型发送.在某些情况下,例如? IS NULL OR someIntegerColumn = ?
,这是必要的.第一个参数是NULL
类型,而第二个参数是INTEGER
类型.
The first instructs the driver to send the null
value as NULL
-type, while the other as INTEGER
-type. This is sometimes necessary in conditions like ? IS NULL OR someIntegerColumn = ?
The first param is of a NULL
-type while the second is of an INTEGER
-type.
但是,确切的区别取决于数据库驱动程序:某些数据库/驱动程序在准备时始终使用服务器指定的类型(并且该驱动程序从其他类型转换为该类型),而另一些则需要或允许在数据库中进行通信.类型指定了应用程序端(然后数据库将转换为实际的本地类型).如果服务器不支持服务器端准备好的语句,则甚至有必要.
However the exact difference depends on the database driver: some databases/drivers always use the type specified by the server on prepare (and the driver converts from other types to that type), while others either require or allow to communicate in the types specified application side (the database then converts to the actual local type). This might even be necessary if the server doesn't support server side prepared statement.
实际上,指定类型可能有一些细微的含义:可能一个导致转换错误,而另一个则没有,或者由于类型转换规则而导致后续转换的行为有所不同.我实际上并没有意识到这种情况的发生.
There may actually be subtle implications for specifying a type: maybe one leads to a conversion error, while the other doesn't, or a subsequent conversion behaves different because of type conversions rules. I am not actually aware of this happening in practice.
这篇关于PreparedStatement setnull方法中Types.INTEGER和Types.NULL之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!