Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the important parameters in Mysql JDBC URL

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly shows you "what are the important parameters in Mysql JDBC URL", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "what are the important parameters in Mysql JDBC URL" this article.

Mysql JDBC Driver

There are two commonly used, one is the mysql driver provided by gjt (Giant Java Tree) organization, and its JDBC Driver name (JAVA class name) is: org.gjt.mm.mysql.Driver

For more information, please see the website: http://www.gjt.org/

Or on this website mysql JDBC Driver (mm.jar)

The other is the official JDBC Driver provided by mysql, and its JAVA class is called com.mysql.jdbc.Driver

Download driver 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] [= parameter value 1] [& parameter name 2] [= parameter value 2].

Only a few important parameters are listed, as shown in the following table:

Parameter name Parameter description default value minimum version requirement

User user name (used to connect to the database) all versions

Password user password (used to connect to the database) all versions

Whether useUnicode uses the Unicode character set. If the parameter characterEncoding is set to gb2312 or gbk, the value of this parameter must be set to true false 1.1g

CharacterEncoding specifies the character encoding when useUnicode is set to true. For example, it can be set to gb2312 or gbk false 1.1g

AutoReconnect do you reconnect automatically when the database connection is broken abnormally? False 1.1

Whether autoReconnectForPools uses the reconnection policy for database connection pooling false 3.1.3

Is the connection set to read-only after the failOverReadOnly automatic reconnection is successful? True 3.0.12

When maxReconnects autoReconnect is set to true, the number of retries of the connection is 31.1

The time interval between two reconnections when initialTimeout autoReconnect is set to true, in seconds 21.1

The timeout (in milliseconds) when a socket connection is established between connectTimeout and the database server. 0 means never timeout, applicable to JDK 1.4 and later 0 3.0.1

The socketTimeout socket operation (read and write) timed out in milliseconds. 0 means never time out 0 3.0.1

For the Chinese environment, usually the connection URL can be set to:

Jdbc:mysql://localhost:3306/test?user=root&password=&useUnicode=true&characterEncoding=gbk&autoReconnect=true&failOverReadOnly=false

In the case of database connection pooling, it is best to set the following two parameters:

AutoReconnect=true&failOverReadOnly=false

It is important to note that in the xml configuration file, the & symbol in url needs to be escaped to &. For example, when configuring database connection pooling in tomcat's server.xml, the mysql jdbc url example is as follows:

Jdbc:mysql://localhost:3306/test?user=root&password=&useUnicode=true&characterEncoding=gbk

& autoReconnect=true&failOverReadOnly=false

These are all the contents of the article "what are the important parameters in Mysql JDBC URL". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report