This topic provides a configuration example of a JDBC connection pool.
When you use JDBC to connect to a database, you need to configure the relevant parameters properly to achieve the best performance of the database. This topic provides some recommended configurations for these parameters.
JDBC connection example:
conn=jdbc:oceanbase://x.x.x.x(ip):xx(port)/xxxx(dbname)?rewriteBatchedStatements=TRUE&allowMultiQueries=TRUE&useLocalSessionState=TRUE&useUnicode=TRUE&characterEncoding=utf-8&socketTimeout=3000000&connectTimeout=60000
This connection example involves the following configuration parameters:
rewriteBatchedStatements: We recommend that you set the value toTRUE.By default, the JDBC driver of OceanBase Database disregards the
executeBatch()statement. It splits a group of SQL statements to be executed in a batch, and sends them to the database one by one. In this case, a batch insert operation is indeed a bunch of single insert operations, resulting in low performance. To implement real batch insertion, you must set this parameter toTRUE, so that the driver can execute SQL statements in batches. You can use the addBatch method to combine multipleINSERTstatements on the same table into oneINSERTstatement that contains multiple values to improve the performance of batch insert operations.You must use the prepareStatement statement to prepare each
INSERTstatement and then execute addBatch. Otherwise, the statements cannot be merged for execution.
allowMultiQueries: We recommend that you set the value toTRUE.The JDBC driver allows you to concatenate multiple SQL statements by semicolons (;) in application code and send them as one SQL statement to the server.
useLocalSessionState: We recommend that you set the value toTRUEto prevent transactions from frequently sending SQL statements for querying session variables to OceanBase Database.Session variables mainly include autocommit, read_only, and transaction isolation.
socketTimeout: the time that the socket waits for the response of the SQL statement when the SQL statement is executed.connectTimeout: the time to wait for the connection to be established.useCursorFetch: We recommend that you set the value toTRUE.For query statements with a large data volume, the database server establishes a cursor and distributes data to clients according to the value of
FetchSize. If this attribute is set toTRUE,useServerPrepStmsis automatically set toTRUE.useServerPrepStms: specifies whether to use the PS protocol to send SQL statements to the database server.If you set this parameter to
TRUE, SQL statements are executed in the following two steps in the database:Send the SQL text that contains a question mark (
?) to the database server for preparation (SQL_audit: request_type=5).Execute the statement based on real values in the database (
SQL_audit: request_type=6).
cachePrepStmts: specifies whether to enable the PS cache to cache PreparedStatments to avoid repeated preparation on the client side and server side.cachePrepStmts=TRUEis applicable to scenarios whereuseServerPrepStmsis set toTRUEand batch execution is performed repeatedly for the same SQL statement. Each batch execution contains the prepare operation and the setting ofexecutecachePrepStmts=TRUE. This avoids repeated preparations.prepStmtCacheSQLLimit: the maximum SQL length allowed for the PS cache.prepStmtCacheSize: the number of SQL statements that can be stored in the PS cache.maxBatchTotalParamsNum: the maximum number of parameters that an SQL statement supports for a batch operation, which is the number of questions marks (?) allowed for an SQL statement. If the number of parameters exceeds the limit, the batch SQL statement will be split.