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);
}


错误:
当我运行我的应用程序时,它显示SQL异常。

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

最佳答案

您的数据库网址必须如下所示:

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


并且您必须在类路径中具有mysql驱动程序。

有关更多详细信息,请参见official documentation

10-07 15:51
查看更多