一直使用 net.sourceforge.jtds.jdbc.Driver 作为我的 MSSQL 驱动程序,用于我所有的应用程序。我在准备好的语句中遇到性能问题,了解到 sendStringParametersAsUnicode=false 应该可以解决问题。不幸的是,我似乎无法让司机接受这个值(value)。我可以让 Microsoft 驱动程序 com.microsoft.sqlserver.jdbc.SQLServerDriver 接受参数就好了:
jdbc:sqlserver://servername:1433;databaseName=dbname;sendStringParametersAsUnicode=false
在 persistence.xml 和我的 ds.xml 中工作。准备好的语句运行速度很快,22 秒内 100 个。
但是,我似乎无法从 JTDS 获得相同的性能提升。它仍然停留在准备好的语句周围,每次迭代需要几秒钟。
我已经尝试了字符串的几种变体,并且在我的测试(带有 Hibernate.connection.url 的 persistence.xml)和带有 JTA 和 ds.xml 的服务器中看到了相同的延迟。
jdbc:jtds:sqlserver://server:1433/dbname;sendStringParametersAsUnicode=false
jdbc:jtds:sqlserver://server:1433;sendStringParametersAsUnicode=false;databaseName=dbname
jdbc:jtds:sqlserver://server:1433;sendStringParametersAsUnicode=false;selectMethod=cursor;socketKeepAlive=true;databaseName=dbname
我读过的所有内容都表明 Microsoft 驱动程序速度较慢,我的公司过去也遇到过问题。如果可能的话,我真的很想使用 JTDS,但是等不到准备好的语句 10 秒!
有人有什么想法吗?
谢谢
最佳答案
documentation对于 sendStringParametersAsUnicode
状态:
Determines whether string parameters are sent to the SQL Server database in Unicode or in the default character encoding of the database. This seriously affects SQL Server 2000 performance since it does not automatically cast the types (as 7.0 does), meaning that if a index column is Unicode and the string is submitted using the default character encoding (or the other way around) SQLServer will perform an index scan instead of an index seek. For Sybase, determines if strings that cannot be encoded in the server's charset are sent as unicode strings. There is a performance hit for the encoding logic so set this option to false if unitext or univarchar data types are not in use or if charset is utf-8.
因此,如果将它包含在您的查询中会使您的性能变差,这表明它不适合您的查询,并且您看到的正是文档警告的问题关于。
如果您看到 MS 驱动程序的性能提升,sendStringParametersAsUnicode
在 JTDS 上的含义可能与在 MS 驱动程序上的含义略有不同。
使用和不使用该选项时,每个驱动程序的性能如何?您使用的是什么版本的 SQL Server?您的查询分析器针对这些查询显示了什么?您的查询是什么?涉及的字段类型是什么?
关于java - 让 JTDS 驱动程序接受 sendStringParametersAsUnicode=false 的问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9075724/