ssm配置jdk8连接mysql8遇到的问题Communications link failure

  • Post author:
  • Post category:mysql


环境:

  • 操作系统:win10 pro
  • ide:intellij IDEA 2018.2.1
  • ssm:spring4.3.5.RELEASE+mybatis3.4.1
  • jdk:因为这里使用spring版本>4导致jdk7接收不到请求,故而使用jdk8

由于调试过程中遇到的问题太多了,真是可怕滴很纳,解决了一个就会又出现新的错误。所以错误信息就没能保存下来,不过没事,以后有有此类问题也就明白其缘由了。

但是呢,作为一个爱学习的好孩子怎能就此放弃呢,于是经过了一天的不懈努力,最终还是被我给拿下了。

首先是出现一个错误在网上查一个,在解决了很多个小bug后,一直卡在了下面这个错误

Error querying database.  Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.)

在网上查到查到的都是因为wait_timeout,但是我设置了之后并没有什么用,依旧是这个错误,还有的说在URL后添加autoReconnect=true,然而还是没用,还有是在数据源dbcp下添加testOnBorrow节点并设置为true,很神奇的是这些都没能解决我的问题。

之后测试发现,这个错误是由于在url后添加了useSSL=true导致的,但是如果不设置控制台会报如下异常,导致我误判,其实并不影响,如想去掉添加useSSL=false即可

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.

之后发现如下提示

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.

大概意思就是推荐使用新的驱动类。

其中看到

这篇帖子

感觉写的挺好,就贴了出来

修改的内容:

jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/mybatis?useSSL=false&serverTimezone=GMT%2B8&characterEncoding=utf8&rewriteBatchedStatements=true
#characterEncoding=utf8  字符编码
#rewriteBatchedStatements=true  批量执行sql
#别忘了更新连接池mysql-connector-java-8.0.11.jar

最后写一点心得:有些时候只看错误信息并能不能帮我们解决问题,要从根源着手,从多方面去看待问题,首先要分析环境,环境如果没问题在去剖析其他原因。



版权声明:本文为qq_35182091原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。