Exception thrown at executeUpdate & DriverManager.getConnection

330 Views Asked by At

I'm trying to connect to a MYSQL database inside java and insert new data. If I use jconnector (jar file) version 5.1.47, an exception is thrown at executeUpdate(String s). If I use version 8 of the jar file, another exception is thrown at Connection myCon = DriverManager.getConnection("jdbc...").

I am using jdk 1.8.0 (version 8) in both scenarios. No error messages, just exceptions. Here is my code which is inside the main function. I can verify that the database is correct on phpmyadmin (I am using xampp to access it).

try {
    final String driver = "com.mysql.cj.jdbc.Driver";
    Class.forName(driver);
    String databaseP = "1234";

    Connection myCon = DriverManager.getConnection("jdbc:mysql://localhost:3306/myDatabase","root",databaseP);
    Statement St = myCon.createStatement();
    String sql = "insert into clients (username, password) values ('marco', 'polo')";
    St.executeUpdate(sql);
//            System.out.println("Insert complete!");
//            //ResultSet rs = St.executeQuery("select * from Clients;");
//
////            while(rs.next()){
////                System.out.println(rs.getString(""));
////            }
    St.close();
    myCon.close();
}
catch(SQLException e){
    System.out.println(e.getErrorCode());
}

In case of exception thrown at Connection myCon: error code is 0, stacktrace is [Ljava.lang.StackTraceElement;@1574691

In case of exception thrown at executeUpdate(sql): error code is 1364, stacktrace is [Ljava.lang.StackTraceElement;@b48321

0

There are 0 best solutions below