0

Code:

package hw02;
import java.sql.*;

public class HW02 
{   
    public static void main(String[] args) throws 
             SQLException,ClassNotFoundException
    {
            Class.forName("com.mysql.jdbc.Driver");

            System.out.println("Driver loaded");

            String url = "jdbc:mysql://localhost/";

            Connection conn = DriverManager.getConnection (url, "root", 
             "sesame");


            System.out.println("Databse connected");
            //Create a statement"
            Statement statement = conn.createStatement();

            ResultSet resultSet = statement.executeQuery("select * from 
            Phones.Products");
            System.out.println("ResultSet completed");

            while (resultSet.next()) 
            {
                System.out.println(resultSet.getString(1)+"\t" + 
                resultSet.getString(2) + "\t" +
                        resultSet.getString(3) + "\t" + "\n");
            }
            //close the connection   
    }  
}

This keeps coming up with a Casting error saying

 Exception in thread "main" 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 

I've looked around and people have suggested changing the connector but i don't know what to do any help would be appreciated.

4
  • "i don't know what to do" Perhaps you should try to do what people have suggested, i.e. replace the MySQL JDBC .jar file with another version. Commented Sep 12, 2018 at 17:42
  • Where is name of database in you code? Commented Sep 12, 2018 at 18:15
  • Possible duplicate of How to connect MySQL to Java program Commented Sep 12, 2018 at 19:03
  • Please edit your question to include the full stack trace. Also include the output of EXPLAIN Phones.Products and SHOW CREATE TABLE Phones.Products to your question. Commented Sep 12, 2018 at 20:12

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.