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.

Vivek Pakmode
  • 1,016
  • 2
  • 10
  • 22
  • *"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. – Andreas Sep 12 '18 at 17:42
  • Where is name of database in you code? – Valentyn Hruzytskyi Sep 12 '18 at 18:15
  • Possible duplicate of [How to connect MySQL to Java program](https://stackoverflow.com/questions/3377151/how-to-connect-mysql-to-java-program) – mohan08p Sep 12 '18 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. – Progman Sep 12 '18 at 20:12

0 Answers0