您的位置:首页 > 编程语言 > Java开发

JDBC规范-java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]The specified SQL type is not supported by this driver

2006-10-12 23:12 966 查看
The java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]The specified SQL type is not supported by this driver is returned from JDBC Driver (DataDirect Connect JDBC, WebSphere embedded Connect JDBC or Microsoft SQL Server 2000 Driver) when an application uses something that is not supported by the JDBC Driver.

The JDBC specification, Chapter 17 Customized Type Mapping, section 17.7 on "NULL Data" states:

"An application uses the existing getObject and setObject mechanism to retrieve
and store SQLData values. We note that when the second parameter, x, of method
PreparedStatement.setObject has the value null, the driver executes the SQL
statement as if the SQL literal NULL had appeared in its place.
void setObject (int i, Object x) throws SQLException;
When parameter x is null, there is no enforcement that the corresponding
argument expression is of a Java type that could successfully be passed to that SQL
statement if its value were not null. The Java programming language null carries
no type information. For example, a null Java programming language variable of
class AntiMatter could be passed as an argument to an SQL statement that
requires a value of SQL type MATTER, and no error would result, even though the
relevant type map object did not permit the translation of MATTER to AntiMatter."

Based on the JDBC specification, it is not recommended to use setObject(int, null).
[b]Solution[/b]
The following 3 setObject methods are available for use with the PreparedStatement object:

setObject(int, Object)

setObject(int, Object, int)

setObject(int, Object, int, int)

Using the second method setObject(int, Object, int) where the third parameter is the targetJDBCType works fine. For example:

setObject(1, null, java.sql.Types.VARCHAR)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐