ClassCastException: java.math.BigInteger 在连接到 MySQL 时不能转换为 java.lang.Long [英] ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long on connect to MySQL

查看:39
本文介绍了ClassCastException: java.math.BigInteger 在连接到 MySQL 时不能转换为 java.lang.Long的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

连接到 MySQL 时,出现错误(见下文).

When connecting to MySQL, I get an error (see below).

点击这里获取代码

我得到这个输出:

run:
Now connecting to databse...

java.sql.SQLException: java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long
java.sql.SQLException: java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:988)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:974)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:919)
    at com.mysql.jdbc.ConnectionImpl.buildCollationMapping(ConnectionImpl.java:1062)
    at com.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3556)
    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2513)
    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2283)
    at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:822)
    at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
    at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:404)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:317)
    at java.sql.DriverManager.getConnection(DriverManager.java:664)
    at java.sql.DriverManager.getConnection(DriverManager.java:247)
    at dbms_basic.Dbms_Basic.main(Dbms_Basic.java:28)
Caused by: java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long
    at com.mysql.jdbc.ConnectionImpl.buildCollationMapping(ConnectionImpl.java:1007)
    ... 15 more
BUILD SUCCESSFUL (total time: 0 seconds)

我该如何解决这个问题?

How can I solve this?

推荐答案

您的错误明确指出无法进行强制转换,因为 java.math.BigInteger 类实例不是 java.lang.Long 类的实例.

Your error clearly says casting is not possible, because a java.math.BigInteger class instance is not an instance of java.lang.Long class.

现在的问题是,谁在哪个级别进行转换,当我们要求 JDBC 驱动程序建立连接时,它在实际将连接的正确工作对象返回给我们之前在幕后做了大量工作.

Now the question arises who is doing casting at what level, when we ask the JDBC driver to make a connection, it is doing lot of work behind the scene before it actually give us back the proper working object of connection.

问题似乎出在您的 MySQL 版本与您的 mysql-connector.jar 版本上.尝试更新版本的 MySQL Connector/J(请参阅 https://dev.mysql.com/downloads/connector/j/ 为最新版本),例如升级到 5.1.47 或 8.0.12 如果您使用的是旧版本.

The problem seems with your version of MySQL in combination with your version of mysql-connector.jar. Try a newer version of MySQL Connector/J (see https://dev.mysql.com/downloads/connector/j/ for the latest version), for example upgrade to 5.1.47 or 8.0.12 if you are using an older version.

这篇关于ClassCastException: java.math.BigInteger 在连接到 MySQL 时不能转换为 java.lang.Long的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆