让 JTDS 驱动程序接受 sendStringParametersAsUnicode=false 时出现问题?

发布于 2024-12-29 20:16:53 字数 1030 浏览 2 评论 0原文

一直使用 net.sourceforge.jtds.jdbc.Driver 作为我所有应用程序的 MSSQL 驱动程序。我在准备好的语句中遇到性能问题,并了解到 sendStringParametersAsUnicode=false 应该可以解决该问题。不幸的是,我似乎无法让司机接受这个值。我可以让 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 秒!

有人有什么想法吗?

谢谢

Been using net.sourceforge.jtds.jdbc.Driver as my driver from MSSQL for all my applications. I had trouble with performance in a prepared statement, and learned that sendStringParametersAsUnicode=false should fix the problem. Unfortunately, I can't seem to get the driver to accept the value. I CAN get the Microsoft driver com.microsoft.sqlserver.jdbc.SQLServerDriver to accept the parameter just fine:

jdbc:sqlserver://servername:1433;databaseName=dbname;sendStringParametersAsUnicode=false

works in a persistence.xml, and in my ds.xml. Prepared statements go quickly, 100 in 22 seconds.

However, I can't seem to get the same performance boost out of JTDS. It still hangs around the prepared statement, taking several seconds on each iteration.

I've tried several variations on the string, and see the same lag in my tests (persistence.xml with Hibernate.connection.url) and Server with JTA and 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

Everything I've read states the Microsoft driver is slower, and my company had issues with it in the past. I'd really like to use JTDS if possible, but can't wait for a prepared statement for 10 seconds!

Anyone had any ideas?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

同尘 2025-01-05 20:16:53

sendStringParametersAsUnicode文档指出:

确定字符串参数是以 Unicode 还是以数据库的默认字符编码发送到 SQL Server 数据库。这严重影响了 SQL Server 2000 的性能,因为它不会自动转换类型(如 7.0 那样),这意味着如果索引列是 Unicode 并且使用默认字符编码(或相反)提交字符串,SQLServer 将执行索引扫描而不是索引查找。对于 Sybase,确定无法在服务器字符集中编码的字符串是否作为 unicode 字符串发送。编码逻辑会影响性能,因此如果未使用 unitext 或 univarchar 数据类型或者字符集为 utf-8,请将此选项设置为 false。

因此,如果将其包含在您的查询中会使您的性能更差,则表明它适合您的查询,并且您所看到的正是文档警告的问题。

如果您看到 MS 驱动程序中的性能提升,则 sendStringParametersAsUnicode 在 JTDS 上的含义可能与 MS 驱动程序上的含义略有不同。

使用和不使用该选项时每个驱动程序的性能如何?您使用什么版本的 SQL Server?您的查询分析器为这些查询显示什么?您的查询是什么以及涉及的字段类型是什么?

The documentation for sendStringParametersAsUnicode states:

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.

So if including it in your query is making your performance worse, that suggests it's not appropriate for your query, and you're seeing exactly the problems the documentation warns about.

If you are seeing a performance boost in the MS driver, it's possible that sendStringParametersAsUnicode has a subtly different meaning on JTDS than on the MS driver.

What's the performance of each driver like with and without the option? What version of SQL Server are you using? What does your query profiler show for these queries? What's your query and what are the types of the fields involved?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文