Mysql JDBC Url Parameter useUnicode = true & characterEncoding = UTF-8

The MYSQL JDBC URL format for Connector / J in the following example:


jdbc:mysql://[host][,failoverhost...][:port]/[database] »
[?propertyName1][=propertyValue1][&propertyName2][=propertyValue2]...

jdbc:mysql://[host:port],[host:port].../[database] »
[?propertyName1][=propertyValue1][&propertyName2][=propertyValue2]...

实例:

jdbc:mysql://127.0.0.1:3306/mysql?useUnicode=true&characterEncoding=utf8

 

Important parameters

Parameter Description Default value is the minimum version required 
user database user name (for connecting to the database) All versions of 
password user password (for connecting to the database) All versions 
useUnicode whether to use Unicode character set, if the parameter is set to characterEncoding gb2312 or gbk, this parameter must be set to 1.1 g false to true 
characterEncoding useUnicode when set to true, the specified character encoding. Or may be set such gb2312 gbk false 1.1g
When autoReconnect when the database connection is disrupted, whether to automatically reconnect? 1.1 false 
when initialTimeout autoReconnect set to true, the time interval between the two re-connection, unit: seconds 2 1.1
autoReconnectForPools whether to use heavy even for a database connection pool 3.1.3 Strategies false 
failOverReadOnly automatically reconnect after a successful connection is set to read-only? true 3.0.12 
When maxReconnects autoReconnect set to true, the number of retries connection 1.1. 3
connectTimeout and database server to establish socket connection timeout, unit: milliseconds. 0 indicates no timeout for JDK 1.4 and later 3.0.1 0 
socketTimeout Socket operation (read and write) times out, unit: ms. 0 means never timeout 0 3.0.1

  Corresponding to the Chinese environment, usually mysql connection URL may be provided:
JDBC: mysql: // localhost:? 3306 / Test User = the root & password = & useUnicode = to true & characterEncoding = GBK & autoReconnect = to true & failOverReadOnly = to false

in the case of using a database connection pool, is preferably set as follows two parameters:
autoReconnect = & failOverReadOnly = to false to true

to be noted that in the xml configuration file, url the need to escape into the & ampersand. When such configuration database connection pool server.xml tomcat in, mysql jdbc url sample as follows:
JDBC: MySQL: // localhost: 3306 / Test User = the root & amp; password = & amp; useUnicode = to true & amp; characterEncoding = GBK?
& Amp; autoReconnect = true & amp; failOverReadOnly = false

Guess you like

Origin www.cnblogs.com/itzyz/p/12153875.html