There are two commonly used, one is the MySQL driver provided by GJT (Giant Java Tree) organization, its JDBC Driver name (Java class name) is: Org.gjt.mm.mysql.Driver
For details, see website: http://www.gjt.org/
or download MySQL JDBC Driver (mm.jar) on this website
The other is the official MySQL-provided JDBC Driver, whose Java class name is: Com.mysql.jdbc.Driver
Driver Download URL: http://dev.mysql.com/downloads/, enter the MySQL connector/j area to download.
The MySQL JDBC URL format is as follows:
jdbc:mysql://[host:port],[host:port].../[database][. Parameter name 1][= argument value 1][& parameter name 2][= argument value 2] ...
Only a few important parameters are listed, as shown in the following table:
Parameter name |
Parameter description |
Default value |
Minimum version requirements |
User |
Database user name (used to connect to database) |
|
All versions |
Password |
User password (used to connect to database) |
|
All versions |
Useunicode |
If the Unicode character set is used, the value of this parameter must be set to True if the parameter characterencoding is set to gb2312 or GBK |
False |
1.1g |
Characterencoding |
When Useunicode is set to True, the character encoding is specified. For example, can be set to gb2312 or GBK |
False |
1.1g |
AutoReConnect |
Is the connection automatically reconnected when the database connection is interrupted abnormally? |
False |
1.1 |
Autoreconnectforpools |
Whether to use a reconnection policy for database connection pooling |
False |
3.1.3 |
Failoverreadonly |
Is the connection set to read-only after the automatic reconnection is successful? |
True |
3.0.12 |
Maxreconnects |
When AutoReConnect is set to true, the number of times to retry the connection |
3 |
1.1 |
Initialtimeout |
When AutoReConnect is set to true, the time interval between two re-interconnects, in seconds |
2 |
1.1 |
ConnectTimeout |
Time-out, in milliseconds, when establishing a socket connection with the database server. 0 means never timeout, for JDK 1.4 and later |
0 |
3.0.1 |
Sockettimeout |
Socket operation (Read-write) timeout, in milliseconds. 0 means never time out |
0 |
3.0.1 |
For the Chinese environment, the MySQL connection URL can usually be set to:
jdbc:mysql://localhost:3306/test?user=root&password=&useunicode=true&characterencoding=gbk& Autoreconnect=true&failoverreadonly=false
In the case of using a database connection pool, it is best to set the following two parameters:
Autoreconnect=true&failoverreadonly=false
Note that in the XML configuration file, the & symbol in the URL needs to be escaped to &. For example, when configuring a database connection pool in Tomcat's server.xml, the MySQL JDBC URL sample is as follows:
Jdbc:mysql://localhost:3306/test?user=root&password=&useunicode=true&characterencoding =gbk
&autoreconnect=true&failoverreadonly=false
For additional parameters, see MySQL JDBC official documentation: MySQL connector/j documentation
Detailed description of each parameter in the JDBC URL