No Suitable Driver Found For My Java Application Code

48 views Asked by At
try
{
 Class.forName("com.mysql.jdbc.Driver");
 Connection con=DriverManager.getConnection
 (
  "jdbc://mysql://3306/localhost/labour",
  "root",
  "pb"
  );

 Statement st=con.createStatement();

 String query="select userid,password from userregiter";
 ResultSet rs= st.executeQuery(query);

 while(rs.next())
 {
  String userid=rs.getString("USERID");
  String password=rs.getString("PASSWORD");

  if ((a.equals(userid)) && (b.equals(password)))
  {
   JOptionPane.showMessageDialog(null, "Username and Password exist");  
  } else {
   JOptionPane.showMessageDialog(null, "Please Check Username and Password ");
  }
 }  

} catch(Exception e) {
 System.out.println(e);
}

ERROR : When I Run My Application It Shows the SQL Exception.

java.sql.SQLException: No suitable driver found for jdbc://mysql://3306/localhost/labour
1

There are 1 answers

1
Jens On BEST ANSWER

Your db url must look like:

DriverManager.getConnection("jdbc:mysql://localhost/labour);

and you must have the mysql driver in your classpath.

See the official documentation for more details.