关于pom中mysql-connector-java的jar包引⼊⾼版本报错的解
决过程
如果你是类似下⾯的2点配置
1.jdbc.properties⽂件
jdbc.sql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/o2o?characterEncoding=utf8
jdbc.username=root
jdbc.password=****
2.POM⽂件
<!-- mysql数据库连接包-->
<!--这个jar包版本如果是8.0.12,则会报错-->
<!-- mvnrepository/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.12</version>
</dependency>
<!-- 数据源c3p0 -->
<!-- mvnrepository/hange/c3p0 -->
<dependency>
<groupId&hange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.5.2</version>
</dependency>
看到如下红⾊字体错误:
Loading class `sql.jdbc.Driver'. This is deprecated. The new driver class is `sql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
你会去将jdbc.sql.jdbc.Driver改成jdbc.sql.jdbc.cj.Driver
结果⼜会报如下红⾊字体错误
### 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\l]
### 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!
我当初就是遇到了这样的问题,查了很多的⽅法,都没能解决,但最后还是死马当活马医,做了如下改动,就解
决了问题,还⼀脸懵逼,怎么会是这个原因呀!
mysql的jar包下载解决⽅法很简单,如下:
1.降低 mysql-connector-java的jar包版本,⽐如降为如下
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
运⾏后再报如下错误
hange.v2.c3p0.DriverManagerDataSource - Could not load sql.jdbc.cj.Driver java.lang.ClassNotFoundException: sql.jdbc.cj.Driver
2.根据上⾯错误提⽰,很容易想到修改jdbc.properties,其实也就是还原最初的样⼦,如下
jdbc.sql.jdbc.Driver
3.再运⾏,OK
最后,总结如下:
<!-- mysql数据库连接包-->
<!--这个jar包版本如果是6.x.x及以上,则会报错,所以改成5.x.x-->
<!-- mvnrepository/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
<!-- 数据源c3p0 -->
<!-- mvnrepository/hange/c3p0 -->
<dependency>
<groupId&hange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.5.2</version>
</dependency>

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。