nt/2k: c:/winnt/system32/
xp/2003: c:/windows/system32/
另外microsoft sql server2005在默认情况下,一些存储过程是关闭着的,需要命令打开:
开启xp_cmdshell:
exec sp_configure 'show advanced options', 1;reconfigure;exec sp_configure
'xp_cmdshell', 1;reconfigure; 这些天因为有数据割接的需求,于是有要写关于批量更新的程序。我们的数据库使用的是sqlserver2005,碰到了一些问题来分享下。
首先注意statement 和preparedstatement的问题
statement sm = cn.createstatement();
sm.addbatch(sql1);
sm.addbatch(sql2);
...
sm.executebatch()
用statement的好处就是每次可以直接传一个sql语句进去,不用管那么多。可是在数据量比较大的时候,应该会对效率有影响。不建议使用。
preparedstatement ps = 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;
开启'openrowset':
exec sp_configure 'show advanced options', 1;reconfigure;exec sp_configure
'ad hoc distributed queries',1;reconfigure;
开启'sp_oacreate':
exec sp_configure 'show advanced options', 1;reconfigure;exec sp
bitscn.com
