JDBC 链接 MySQL URL 配置参数记录

原创
2019/01/22 16:32
阅读数 1K
jdbc:mysql://localhost/dbName?useUnicode=true&useSSL=true&zeroDateTimeBehavior=convertToNull&serverTimezone=UTC&autoReconnect=true&allowMultiQueries=true&failOverReadOnly=false

 

1. useSSL = true 

避免出现如下警告或错误

Establishing SSL connection without server's identity verification is not recommended. 
According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. 
For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. 
You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.

 

2. zeroDateTimeBehavior=convertToNull

防止数据库中的日期格式为 0000-00-00 00:00:00 导致查询报错:

Caused by: java.sql.SQLException: Value '0000-00-00' can not be represented as java.sql.Timestamp
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:964) ~[mysql-connector-java-5.1.42.jar:5.1.42]
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:897) ~[mysql-connector-java-5.1.42.jar:5.1.42]
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:886) ~[mysql-connector-java-5.1.42.jar:5.1.42]
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860) ~[mysql-connector-java-5.1.42.jar:5.1.42]

 

3. allowMultiQueries=true

开启 MySQL 批量执行 SQL

 

4. autoReconnect=true 

防止链接突然中断,开启自动重连功能

 

5. maxReconnects=5

最大重连次数

 

6. useUnicode=true&characterEncoding=utf8bm4

指定编码格式

 

&

 

展开阅读全文
打赏
0
2 收藏
分享
加载中
更多评论
打赏
0 评论
2 收藏
0
分享
返回顶部
顶部