数据库
首页 > 数据库> > java-包com.mysql.jdbc.exceptions.jdbc4在Mysql Connector / J 8中不存在

java-包com.mysql.jdbc.exceptions.jdbc4在Mysql Connector / J 8中不存在

作者:互联网

mysql-connector-java版本5.1.x的maven依赖性升级到8.0.x后,编译时会收到以下错误:

[ERROR] /home/dev/testproject/src/main/java/DatabaseOperation.java:20: error: package com.mysql.jdbc.exceptions.jdbc4 does not exist
[ERROR] import com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException;

[ERROR] /home/dev/testproject/src/main/java/DatabaseService.java:15: error: package com.mysql.jdbc.exceptions.jdbc4 does not exist
[ERROR] import com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException;

显然com.mysql.jdbc.exceptions.jdbc4已删除,迁移文档中没有任何弃用或注释.现在有什么选择?

解决方法:

确实,在发行说明或迁移文档中没有提到这一点.我在MySQL论坛:Connector/J 8, catching primary key violations上找到了相关主题.这里是MySQL代表的回答:

You can catch java.sql.SQLIntegrityConstraintViolationException.
MySQLIntegrityConstraintViolationException was needed because of c/J
5.1 hybrid code, it does nothing specific just extends this java.sql.SQLIntegrityConstraintViolationException.

换句话说,已删除该程序包以重用现有的java.sql异常类,这是一件好事,但仍应进行记录.作为上述讨论的结果,错误报告已创建:Bug #91439 upgrade guide needs to inform of removed/refactored exceptions

当我进一步检查项目中的错误时,我发现了这3个异常及其java.sql映射:

> com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException->
java.sql.SQLSyntaxErrorException
> com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException
-> java.sql.SQLIntegrityConstraintViolationException
> com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException
-> java.sql.SQLTransactionRollbackException

(而且我猜jdbc4包中的任何其他MySQL特定于MySQL的异常也都映射到java.sql包中的类似SQL异常)

标签:mysql-connector,java
来源: https://codeday.me/bug/20191108/2009886.html