SQL Server JDBC 1.0 中关于executeBatch()方法的两个bug
作者: Jet Mah from Java堂
声明: 可以非商业性任意转载, 转载时请务必以超链接形式标明文章原始出处、作者信息及此声明!
SQL Server JDBC的bug真是多多啊, 今天又发现两个很奇怪的错误, 查了网上的一些资料, 果然是驱动的bug. 情况是这样的:
将SQL Server JDBC的连接字段中SelectMethod设置为cursor, 然后执行下面一段代码:
- PreparedStatement stmt = connection.prepareStatement("insert into table1
- values (?, ?)");
- stmt.setInt(1, 1);
- stmt.setInt(2, 2);
- stmt.addBatch();
- stmt.executeBatch();
- stmt.close();
这个时候会产生 “sp_cursoropen/sp_cursorprepare: 语句参数只能是单个 SELECT 语句或单个存储过程。” 的SQLServerException, 同时数据不能写入到数据库中.
第二个错误是使用CallableStatement调用SQL Server的存储过程的时候, 如果使用executeBatch()方法的时候, 数据不能进行写入或更新, 并且没有抛出任何的异常.
查了一下微软的bug中心, 发现以上两个错误果然是JDBC的bug.
Bug Details: JDBC Driver executeBatch does not work with INSERT statement
http://lab.msdn.microsoft.com/ProductFeedback/viewFeedback.aspx?feedbackid=e13a8009-7466-4803-ba19-6bfd4b5f8966
Bug Details: Statement.execute() returns incorrect results for stored procedures
http://lab.msdn.microsoft.com/ProductFeedback/viewfeedback.aspx?feedbackid=dc43eb80-69b5-4137-8671-9f4e813ce259
bug记录上面显示状态为fixed, 但是对外公开的最新的驱动还没有更新, 只能是耐心的等待了 ![]()
参考资料:
Batch inserts dont work with PreparedStatement and selectMethod=cursor
http://groups.google.com/group/microsoft.public.sqlserver.jdbcdriver/browse_thread/thread/97b17f5b551ad146/385a82eb5315dccc?q=Batch+inserts+dont+work+&rnum=1
[...] Previous Post 让Apache支持asp的iASP [...]
Pingback by » 拿到了SQL Server JDBC V1.1 CTP驱动 [Java堂] — 2007年10月25日 @ 3:35 上午