找不到适合我的Java应用程序代码的驱动程序

时间:2015-06-08 08:53:53

标签: java jdbc

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

1 个答案:

答案 0 :(得分:1)

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

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

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

有关详细信息,请参阅official documentation