Two MySQL JDBC drivers are commonly used. One is the MySQL driver provided by gjt (giant Java tree). The JDBC driver name (Java class name) is Org. gjt. mm. mySQL. driver
For more information, see website: http://www.gjt.org/
The other is the JDBC driver officially provided by MySQL. Its Java class name is com. MySQL. JDBC. Driver.
Driver download URL: http://dev.mysql.com/downloads/. download the driver from the MySQL connector/J region.
The URL format of MySQL JDBC is as follows:
JDBC: mysql: // [host: Port]/[database] [? Parameter Name 1] [= parameter value 1] [& parameter name 2] [= parameter value 2]...
Parameter Name |
Parameter description |
Default Value |
Minimum Version requirements |
User |
Database username (used to connect to the database) |
|
All Versions |
Password |
User Password (used to connect to the database) |
|
All Versions |
Useunicode |
Whether to use the Unicode character set. If the characterencoding parameter is set to gb2312 or GBK, the value of this parameter must be set to true. |
False |
1.1 GB |
Characterencoding |
Specify the character encoding when useunicode is set to true. For example, you can set it to gb2312 or GBK. |
False |
1.1 GB |
Autoreconnect |
Will the database be automatically reconnected when the database connection is interrupted abnormally? |
False |
1.1 |
Autoreconnectforpools |
Whether to use the reconnection policy for the database connection pool |
False |
3.1.3 |
Failoverreadonly |
After automatic reconnection is successful, is the connection set to read-only? |
True |
3.0.12 |
Maxreconnects |
Number of Retries when autoreconnect is set to true |
3 |
1.1 |
Initialtimeout |
The interval between two reconnection attempts when autoreconnect is set to true. Unit: seconds. |
2 |
1.1 |
Connecttimeout |
Timeout when establishing a socket connection with the database server, in milliseconds. 0 indicates never timeout. Applicable to JDK 1.4 and later versions. |
0 |
3.0.1 |
Sockettimeout |
Socket operation (read/write) Timeout, in milliseconds. 0 indicates never timeout |
0 |
3.0.1 |
The connection URL of MySQL can be set:
JDBC: mysql: /// localhost: 3306/test? User = root & Password = & useunicode = true & characterencoding = GBK & autoreconnect = true & failoverreadonly = false
When using the database connection pool, it is best to set the following two parameters:
Autoreconnect = true & failoverreadonly = false
Note that the & symbol in the URL must be escaped in the XML configuration file. For example, when you configure the database connection pool in Tomcat server. XML, the MySQL jdbc url sample is as follows:
JDBC: mysql: /// localhost: 3306/test? User = root & amp; Password = & amp; useunicode = true & amp; characterencoding = GBK
& Amp; autoreconnect = true & amp; failoverreadonly = false