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

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).
 
Solution
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)
 
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值