关于pom中mysql-connector-java的jar包引入高版本报错的解决过程

如果你是类似下面的2点配置

1.jdbc.properties文件

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/o2o?characterEncoding=utf8
jdbc.username=root
jdbc.password=****

 

2.POM文件




  mysql
  mysql-connector-java
  8.0.12




  com.mchange
  c3p0
  0.9.5.2

 

看到如下红色字体错误:

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.jdbc.Driver改成jdbc.driver=com.mysql.jdbc.cj.Driver

结果又会报如下红色字体错误

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!
### The error may exist in file [D:\SSM_maven\o2o\target\classes\mapper\AreaDao.xml]
### The error may involve com.imooc.o2o.dao.AreaDao.queryArea
### The error occurred while executing a query
### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!

 

我当初就是遇到了这样的问题,查了很多的方法,都没能解决,但最后还是死马当活马医,做了如下改动,就解决了问题,还一脸懵逼,怎么会是这个原因呀!

解决方法很简单,如下:

1.降低 mysql-connector-java的jar包版本,比如降为如下

mysql-connector-java
  5.1.38

运行后再报如下错误

 WARN com.mchange.v2.c3p0.DriverManagerDataSource - Could not load driverClass com.mysql.jdbc.cj.Driver
java.lang.ClassNotFoundException: com.mysql.jdbc.cj.Driver

 

2.根据上面错误提示,很容易想到修改jdbc.properties,其实也就是还原最初的样子,如下

jdbc.driver=com.mysql.jdbc.Driver

3.再运行,OK

 

最后,总结如下:





  mysql
  mysql-connector-java
  5.1.38




  com.mchange
  c3p0
  0.9.5.2

 

你可能感兴趣的:(pom,maven,ssm,SSM,maven)