Classcastexception: Java.Math.Biginteger Cannot Be Cast to Java.Lang.Long on Connect to MySQL

ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long on connect to MySQL

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

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.

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.

my sql :java.math.BigInteger cannot be cast to java.lang.Long

Judging by the syntax, the query that you wrote is wrong. You can check the insert statement format here. So basically what you should write is something in the line of:

insert into login.tables (user_id, password) values("some_user", "s3cr3t")

instead, it seems that you are not listing the column names first, then assigning the values, but putting the username value in the column names space and the password in the values part.

java.math.BigInteger cannot be cast to java.lang.Integer

You can use:

Integer grandChildCount = ((BigInteger) result[1]).intValue();

Or perhaps cast to Number to cover both Integer and BigInteger values.



Related Topics



Leave a reply



Submit