Questions about JDBC Connection Parameters

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: JDBC连接参数疑问

| username: Ming

I have a question about the prepStmtCacheSqlLimit parameter in the Java best practices section of the official TiDB documentation. Its default value is 256, and I want to set it to 2048. However, I encountered an error.

Error message:
The connection property ‘prepStmtCacheSqlLimit’ only accepts integer values. The value ‘2048’ cannot be converted to an integer.

Can you please explain how this value is calculated and why 2048 is not acceptable?

| username: Kongdom | Original post link

How did you set it? Did you set it as a string?

| username: Ming | Original post link

prepStmtCacheSqlLimit=2048

| username: Ming | Original post link

That’s how it was entered.

| username: Kongdom | Original post link

:rofl: Judging by the error message, could there be a bug here? Does setting it to 256 not cause an error?

| username: Ming | Original post link

I have seen that it can be set to 1000, but I don’t know how this is calculated.

| username: Icemap | Original post link

I did a simple test using this code, and it couldn’t be reproduced under JDK 17 / target Java version 11 / 8.0.29 Driver version / macOS. Can you provide your reproduction code?

public class App 
{
    public static void main( String[] args ) throws SQLException {
        String dbUrl = "jdbc:mysql://192.168.31.31:4000/test?user=root&password=&prepStmtCacheSqlLimit=2048";

        try (Connection connection = DriverManager.getConnection(dbUrl)) {
            ResultSet rs = connection.createStatement().executeQuery("SELECT VERSION()");
            while (rs.next()) {
                System.out.println(rs.getString(1));
            }
        }
    }
}
| username: Ming | Original post link

spring.datasource.url

jdbc:mysql://xxxxx:xxxx/test?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&uselegacyDatetimeCode=false&serverTimezone=UTC&useServerPrepStmts=true&cachePrepStmts=true&useConfig=maxPerformance&prepStmtCacheSize=1000&prepStmtCacheSqlLimit=2048

| username: Ming | Original post link

I handed the parameters over to the developers to handle, and the diagram they provided looks roughly like this.

| username: Icemap | Original post link

I used the connection string provided here as a parameter to configure Spring, but I still couldn’t reproduce the issue. You can use the example code here, where the spring-jpa-hibernate project uses Spring Boot. You can simply change the spring.datasource.url parameter in the application.yml, start the service, and run the tests.

| username: Kongdom | Original post link

:sweat_smile: I think the error is quite obvious. Should we ask the development team to investigate? It might be that the conversion to a character happened on their side.

| username: Ming | Original post link

Okay, got it.

| username: system | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.