idea搭建SSM框架时JDBC启动失败错误集锦

1、The driver has not received any packets from the server

在jdbc连接中,加入参数:

 

jdbc.url=jdbc:mysql://localhost:3306/totosea?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&failOverReadOnly=false

并将mysql的安装目录下找到my.ini (要找到my.ini,要先去找到ProgramData,这里要先打开显示隐藏文件的设置,即WIN+R打开运行模式,输入%ProgramData%),在文末添加:

wait_timeout=31536000

interactive_timeout=31536000

重启失败,又遇到问题2:

2、MYSQL:WARN: Establishing SSL connection without server's identity verification is not recommended.

在JDBC连接Mysql数据库的过程中出现了如下的警告信息:

WARN: 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.

是Mysql数据库的SSL连接问题,提示警告不建议使用没有带服务器身份验证的SSL连接,是在MYSQL5.5.45+, 5.6.26+ and 5.7.6+版本中才有的这个问题。

解决办法在警告中已经说明了(为什么不看,英文白学了15年,还是太懒):

  A、在数据库连接的url中添加useSSL=false;

  B、url中添加useSSL=true,并且提供服务器的验证证书。

如果只是做一个测试的话,没必要搞证书那么麻烦啦,在连接后添加一个useSSL=false即可,例如:

 

jdbc:mysql://localhost:3306/test?useSSL=false

 

在使用Java进行JDBC连接的时候,可以在Properties对象中设置useSSL的值为false,但是和写在链接中是一样的:

Properties properties = new Properties();
properties.setProperty("user", "root");
properties.setProperty("password", "milos23);
properties.setProperty("useSSL", "false");
properties.setProperty("autoReconnect", "true");
try (Connection conn = DriverManager.getConnection(connectionUrl, properties)) {
    ...
} catch (SQLException e) {
    ...
}

设置了以上信息后,数据库依旧没有运行成功

3、JDBC中The server time zone value '???ú±ê×??±??' is ............. 的错误

 

Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. 
The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary. Tue May 15 21:38:04 CST 2018 WARN: 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. java.sql.SQLException: The server time zone value '???ú±ê×??±??' is unrecognized or represents more than one time zone.
You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support. at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:127) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:95) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:87) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:61) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:71) at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:76) at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:862) at com.mysql.cj.jdbc.ConnectionImpl.
<init>(ConnectionImpl.java:444) at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:230)....

 

出现这个的原因是因为 mysql返回的时间总是有问题,比实际时间要早8小时。

 

解决办法:在jdbc连接的url后面加上serverTimezone=GMT即可解决问题,如果需要使用gmt+8时区,需要写成GMT%2B8

public static final String URL="jdbc:mysql://localhost:3306/jdbc01?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false";//链接的mysql

结合这三个错误,得到jdbc的连接如下:

jdbc.url=jdbc:mysql://localhost:3306/ssm?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&failOverReadOnly=false&serverTimezone=GMT%2B8&useSSL=false

 

posted @ 2019-07-11 15:31  AliveLIP  阅读(598)  评论(0)    收藏  举报