Previously written JDBC connection is always direct copy, for the connection database of the jar where the download, the corresponding driver class is which, the database connection string how to find and so has not done, today from zero began to complete again.
The database used is MySQL
First, the case of MySQL has been installed
If you have MySQL installed on your computer, congratulations you don't have to search the Internet. Look for the "Connector J" folder under the installation path, there will be a corresponding jar package, source code and related documents.
The jar package is found, and the next step is to find out where to find the driver and URL.
In the "Docs" folder in "Connector J", there are two explanatory documents for both Web and PDF. Both of these things are the same.
This opens the HTML version of the
And then
Okay, here's the driver and url we need. As for the PropertyName in the URL, there is nothing to say.
second, no MySQL installed on the computer
If there is no installation, there is no need to download a MySQL database to install, we go to the official website to see.
Www. mysql. com
And then
And then
And then
And then
Here is the download page
The document is the same as in the first method, so it is not covered.
Third, the URL of the PropertyName have what
PropertyName is also described in the documentation
But English seems bored after all, the following turn from online a person's summary, reprint connection: http://blog.163.com/oyhj_nicholas/blog/static/323592520104941755831/
The MySQL JDBC URL format is as follows:
jdbc:mysql://[host:port]/[database][. Parameter name 1][= argument value 1][& parameter name 2][= argument value 2] ...
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. 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
Find the MySQL database connection jar package and the corresponding driver and URLs