数据库
首页 > 数据库> > 连接JDBC报错:com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create conn

连接JDBC报错:com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create conn

作者:互联网

问题:
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,jdbc4,driver,报错,mysql,com,class
来源: https://www.cnblogs.com/melodyjerry/p/13587027.html