sqlserver2000的jdbc驱动和PreparedStatement的性能问题。
2004-11-09 19:48
417 查看
人们都说用PreparedStatement会提高程序的性能。我在sqlserver下面试了一下,结果令我大吃一惊 。
connection.setAutoCommit(false);
pstmt = connection.prepareStatement(sql);
pstmt.setFetchSize(100);
pstmt.setString(1,"026011009004");
ResultSet rs = pstmt.executeQuery();
connection.commit();
做一个查询竟然需要6秒多,在数据库里数据很少的情况下很快的,但是数据库表里面的记录多到100万的时候查询真的很慢。一开始我怀疑是jdbc驱动的事情可是我换了一个sqlserver的jdbc驱动结果还是一样。
当向pstmt 设置int类型的参数时性能又正常了。
为什么设置string类型的时候会出现的?令我百思不得其解。
我查看sqlserver jdbc 驱动的文档 发现里面有这么一个参数:
SendStringParameters
AsUnicode
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
原来string型的参数传到数据库里面默认是转换成unicode的。
当我把SendStringParameters 设置成false时,查询的性能得到了巨大的提高,原来用6秒的查询现在只需要16毫秒了。
问题解决了。
connection.setAutoCommit(false);
pstmt = connection.prepareStatement(sql);
pstmt.setFetchSize(100);
pstmt.setString(1,"026011009004");
ResultSet rs = pstmt.executeQuery();
connection.commit();
做一个查询竟然需要6秒多,在数据库里数据很少的情况下很快的,但是数据库表里面的记录多到100万的时候查询真的很慢。一开始我怀疑是jdbc驱动的事情可是我换了一个sqlserver的jdbc驱动结果还是一样。
当向pstmt 设置int类型的参数时性能又正常了。
为什么设置string类型的时候会出现的?令我百思不得其解。
我查看sqlserver jdbc 驱动的文档 发现里面有这么一个参数:
SendStringParameters
AsUnicode
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
原来string型的参数传到数据库里面默认是转换成unicode的。
当我把SendStringParameters 设置成false时,查询的性能得到了巨大的提高,原来用6秒的查询现在只需要16毫秒了。
问题解决了。
相关文章推荐
- sqlserver2000的jdbc驱动和PreparedStatement的性能问题。
- JSP连接各类数据库大全SQLServer2000 JDBC驱动的完整安装及测试?
- 解决maven官方库中没有oracle jdbc驱动问题 编辑
- Mysql JDBC驱动版本与Mysql版本的对应问题
- Sqoop安装与MapReduce读MySql写HDFS加载不了JDBC驱动问题
- 向maven仓库中添加,oracle jdbc驱动问题
- JSP连接各类数据库大全SQLServer2000 JDBC驱动的完整安装及测试?
- JDBC for MySQL驱动版本问题
- 使用连接mysql的jdbc驱动最新版引发的问题
- 尽管关于Java中文问题的讨论已经相当多了,但由于Java的相关技术标准繁多,面向Java的Web服务器、应用服务器以及JDBC数据库驱动等都没有官方的标准,所以Java应用在处理中文时所存在的问
- 关于Sql Server JDBC 4.0驱动在maven中引入失败的问题
- JSP连接各类数据库大全SQLServer2000 JDBC驱动的完整安装及测试?
- WebSphere中DB2JDBC驱动配置问题
- SQL2000的jdbc驱动问题【转】
- 使用MySQL的jdbc驱动关于时区引发的问题
- Oracle12c jdbc版本驱动问题
- JSP连接各类数据库大全SQLServer2000 JDBC驱动的完整安装及测试?
- mysql驱动引起的jdbc4.MySQLSyntaxErrorException: Unknown character set: 'utf8mb4'问题解决
- JDBC连接sqlserver2000问题
- oracle11G JDBC驱动的问题