After upgrading the maven dependency for mysql-connector-java
version 5.1.x to 8.0.x the following errors are received upon compilation:
[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;
Apparently the com.mysql.jdbc.exceptions.jdbc4 was removed without any deprecation or a note in the migration docs. What is the alternative now?
Indeed, there was no mention of that in the release notes or migration docs. I found the relevant topic at MySQL Forums: Connector/J 8, catching primary key violations. Here is an answer from MySQL representative there:
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.
In other words, the package has been removed to reuse the existing java.sql
exception classes, which is a good thing, but still should've been documented. As a result of the forementioned discussion, the bug report has been created: Bug #91439 upgrade guide needs to inform of removed/refactored exceptions
As I further inspected the errors in my project, I found these 3 exceptions and their java.sql
mappings:
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
(and I guess any other MySQL-specific exception from jdbc4 package also maps to the analogous SQL-exception from java.sql package)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With