jdbc操作SqlServer时执行ps.executeQuery()速度很慢(时间很长)的解决方法

[size=large]jdbc链接SqlServer时发现执行查询语句速度很慢,查了很多方法没找到解决方法

于是在SqlServer的jdbc驱动文档中(如果机器上安装了安驱动,在安装目录下找到\Help\jdbcsqlsrv3.html文件)有这样一个属性[/size]
[size=xx-large]SendStringParametersAsUnicode[/size]
[size=large]该属性的表述如下:
SendStringParametersAsUnicode={true | false}. Determines whether string parameters are sent to the SQL Server database in Unicode or in the default character encoding of the database. True means that string parameters are sent to SQL Server in Unicode. False means that they are sent in the default encoding, which can improve performance because the server does not need to convert Unicode characters to the default encoding. You should, however, use default encoding only if the parameter string data that you specify is consistent with the default encoding of the database.
The default is true.
如果该属性的值为true(默认),则将string参数以unicode形式传到数据库;
如果将该属性值设为false,则已默认字符编码传到数据库,这样可以提高性能,原因是服务器不需要编码字符转换

于是在jdbc的URL后面加上sendStringParametersAsUnicode=false后,发现执行速度变快了[/size]

[size=x-large]PS:虽然用了这个方法,但是有时速度还是会慢,因为是在本机做的测试,可能也会和机器性能有关,所以有条件的朋友可以在服务器上进行测试,看看前后的性能是否真的改变了[/size]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值