我在写了段连接数据库并进行验证的代码,可是不管我输入的Id和Password是否正确他都只是显示“用户名或密码错误”,不知道是为什么?不知道是哪里出错了!代码如下:
if (jTextField1.getText().equals("")) {
JOptionPane.showMessageDialog(null, "姓名不能为空!");
}
else if (jPasswordField1.getPassword().length == 0) {
JOptionPane.showMessageDialog(null, "密码不能为空!");
}
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (ClassNotFoundException ce) {
System.out.println("驱动未被找到");
}
try {
String url = "jdbc:odbc:NetBar";
String str = "select * from Card where Id='" +
jTextField1.getText() + "' and Password='" +
jPasswordField1.getPassword() + "'";
Connection con = DriverManager.getConnection(url, "Card",
"123456");
Statement s = con.createStatement();
ResultSet rs = s.executeQuery(str);
if (rs.next()) {
JOptionPane.showMessageDialog(null, "登陆成功!");
}
else {
JOptionPane.showMessageDialog(null, "姓名或密码输入输入错误!");
}
}
catch (SQLException ce) {
System.out.println(ce);
}
数据库出错!