连接JDBC报错:com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.

问题:
Spring整合Mybatis时候,出现数据库连接异常:

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.

分析:

找了好半天的原因,最后发现是相关jdbc驱动包版本太低

解决方法:

下载最新版的mysql-connector-java即可。
虽然可以连接成功,但是控制台还是提示:

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.

修改一下mybatis-config.xml

<!--<property name="driver" value="com.mysql.jdbc.Driver"/>-->
<property name="driver" value="com.mysql.cj.jdbc.Driver"/>

连接JDBC报错:com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.

上一篇:mysql 8.0设置日期为0000-00-00 00:00:00时报错


下一篇:dbus-python的API及示例