Unable to Connect to MySQL: "java.math.BigInteger cannot be cast to java.lang.Long"
Problem:
When attempting to connect to a MySQL database, the following error occurs:
java.sql.SQLException: java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long
Explanation:
This error indicates that the Java virtual machine is encountering an issue when trying to convert an instance of the java.math.BigInteger class to an instance of the java.lang.Long class. This casting is performed internally by the MySQL Connector/J during the connection process.
Resolution:
The recommended resolution is to update the MySQL Connector/J library to a newer version. This is because earlier versions of the library may have compatibility issues with the driver used to connect to MySQL.
To resolve the issue:
For example, if using Maven, add the following dependency to the project's pom.xml file:
<dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.12</version> <!-- Latest version as of this writing --> </dependency>
The above is the detailed content of Why am I getting a 'java.math.BigInteger cannot be cast to java.lang.Long' error when connecting to MySQL?. For more information, please follow other related articles on the PHP Chinese website!