mssql-jdbc: SendStringParametersAsUnicode parameter not working

SendStringParametersAsUnicode attribute is set to “false” after the JDBC use prepareStatement SQL execution CHAR type query still very slowly

Based on SqlServer2008, the JDBC driver version is 6.2.2.jre8

Through a series of validation, in fact, in a single primary key OR query, actual sendStringParametersAsUnicode attribute is set to “false” is to take effect.

For example, the following SQL precompiled can take effect, The speed is normal.

Note that the ID here is of the char type, and this SQL will be slow before the property is configured

SELECT * FROM FS_InpatientContact WHERE ([ID]=?) OR ([ID]=?) OR ([ID]=?) OR ([ID]=?) OR ([ID]=?)......

However, this property seems to be invalid in another table query, where ITEM_CODE is of type char and REP_NO is of type numeric. Therefore, I speculate that it may have failed in the case of multiple primary keys.

SELECT * FROM AS_REPENTRY WHERE ([ITEM_CODE]=? AND [REP_NO]=?) OR ([ITEM_CODE]=? AND [REP_NO]=?) OR ([ITEM_CODE]=? AND [REP_NO]=?)......

With this in mind I Debug the source code image

Through the debug source setObject method, which can be found in fact sendStringParametersAsUnicode properties of false was effective. However, when actually sent to the server, it should still be in Unicode format, so the conversion will be time-consuming, resulting in extremely slow SQL queries.

This problem is more obvious in the larger the data volume of the table

Above is my investigation process, but also hope guys to give some advice

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Comments: 17 (10 by maintainers)

Most upvoted comments

Hi @Jeffery-Wasty

In fact, in the context of the initial problem, the database was running on windows server and the program connecting to the SQL was running on Linux. The thing about docker last time is that I wanted to keep our environment the same with a common image instance, so you can try to start the image instance with the container and run my duplicate code earlier to test it. Because I repeated the same problem in the container image environment