Home > Database > Mysql Tutorial > body text

sql server 批量更新问题的解决方法

WBOY
Release: 2016-06-07 17:47:05
Original
1152 people have browsed it

Statement 和PreparedStatement的问题
Statement sm = cn.createStatement();
sm.addBatch(sql1);
sm.addBatch(sql2);
...
sm.executeBatch()
用Statement的好处就是每次可以直接传一个SQL语句进去,不用管那么多。可是在数据量比较大的时候,应该会对效率有影响。不建议使用。
PreparedStatement = cn.preparedStatement(sql);
{
 ps.setXXX(1,xxx);
 ...
 ps.addBatch();
}
ps.executeBatch();
PreparedStatement是会预编译的,只要一条SQL,不断动态设值,然后addBatch(),在数据量大的时候比较好,非常建议使用。
还有就是JDBC的驱动问题,很多同志可能还是在用2000的驱动呢,没有用批量更新的程序没有多大问题,可是一旦用了批量更新,出现很多问题,
反正很卡,慢。还可以更新不了哦。
我强烈建议大家更新JDBC驱动。
但是如果出现
SQLServerException: sp_cursoropen/sp_cursorprepare: 该语句参数只能是一个批或带有单个 SELECT 语句的存储过程,且不带 FOR BROWSE、COMPUTE BY 或变量赋值。
应该就是JDBC的版本问题,1.0的驱动有这个问题,好像不支持批量更新,我建议大家使用1.2
我测试过了,完全没有问题!
提供一些数据连接参数
jdbc.driverClassName:com.microsoft.sqlserver.jdbc.SQLServerDriver
jdbc.url:jdbc:sqlserver://127.0.0.1:1444;databaseName=fax;selectMethod=cursor;

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!