GhostHacks96 GhostHacks96 - 7 months ago 15
Java Question

Java jdbc mysql error

I'm working on a program for fun but the

MySQL
driver and connection code isn't working properly I got the error

Error: no suitable driver found


MeanWhile my code contains the
Class.forName("com.mysql.jdbc.Driver");
line. I have the newest
MySQL
jar file in my class path. any suggestions I could try to fix the problem

private void connect() {
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection(URL,user,pass);
stmt = con.createStatement();
} catch (Exception e) {
error = true;
e.printStackTrace();
}
}

Answer

Your issue is in the syntax of the URL which is not correct you forgot the colon after mysql, it should be jdbc:mysql://... for more details about the syntax of the URL in case of mysql please refer to this web page