People say that using PreparedStatement will increase the performance of the program. I tried it under Sql Server, and I was shocked.
Connection.SetAutocommit (False);
PSTMT = Connection.PrepareStatement (SQL);
PSTMT.SetFetchSize (100);
PSTMT.SetString (1, "026011009004");
ResultSet RS = pstmt.executeQuery ();
CONNECTION.COMMIT ();
It takes more than 6 seconds to make a query. When the data database is very small, the query is really slow when the record is more than 1 million in the database table. At first I suspect is a JDBC driver, but I changed a JDBC driver result of SQLServer or the same.
When the PSTMT sets the INT type parameter, the performance is normal.
Why do you appear when setting the string type? I can't help me.
I am looking at the SQLServer JDBC driver discovery to have such a parameter:
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 data.
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, Uses Use default encoding Only The Parameter
String Data That You Specify IS Consistent with the Default
Encoding of the database.
The Default Is True
The original String type parameter is transmitted to the database by default to Unicode.
When I set SendStringParameters to false, the performance of the query has been greatly improved, and the original query is now only 16 milliseconds now.
The problem is solved.