0

I found similar problems with this but haven't found a solution yet. I am making a create account form with a mysql connection but when I try to click the create button, I have this error.enter image description here

Here is my code for myConnection

import java.sql.Connection;
import java.sql.DriverManager;

public class myConnection {
    
    public static Connection getConnection() {
        
        Connection con = null;
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            con = DriverManager.getConnection("jdbc:mysql://localhost/javacontactsapp", "root", "");
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }
        
        return con;
    }
}

Output when I changed it to ex.printStackTrace(); enter image description here

        Connection con = null;
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            con = DriverManager.getConnection("jdbc:mysql://localhost/javacontactsapp", "root", "");
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        
        return con;
WiloWisk
  • 137
  • 3
  • 10
  • 1
    So you ate the exception and returned null. What was the message on the exception? It would be better to have the exception type and stack trace too. Not all exceptions have a message. And you might as well throw the original exception, as shown here you will just get a different unrelated exception later. – Nathan Hughes Jun 04 '21 at 02:28
  • change `System.out.println(ex.getMessage());` to `ex.printStackTrace();` and then show us the output. – Scary Wombat Jun 04 '21 at 02:28
  • @ScaryWombat I have edited the post to display the output. – WiloWisk Jun 04 '21 at 02:53
  • 2
    `ClassNotFoundException` means that the `jar` file that you are using needs to be added to your classpath. See https://stackoverflow.com/questions/17408769/how-do-i-resolve-classnotfoundexception – Scary Wombat Jun 04 '21 at 02:54
  • Post text here rather than images wherever practicable. – Basil Bourque Jun 04 '21 at 02:58

0 Answers0