Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root", "123456");
String sql="select name,password from user";
Statement st=con.createStatement();
ResultSet rs=st.executeQuery(sql);
if(rs.next()){
//System.out.print("hello word");
if(rs.getString("name").equals(name)&& rs.getString("password").equals(pass)){
System.out.print("hello word");
jf.setVisible(false);
new MyFrame();
}
else{
JOptionPane jo=new JOptionPane();
jo.showMessageDialog(jf, " 用户名密码错误 请 出 新 输 入 ! ", "错 误 提示", JOptionPane.CLOSED_OPTION);
}
}
我把用户名和密码都写正确为什么还是显示用户密码错误的对话框 并且显示2便
rs.close();
}
catch(Exception ex){
System.out.println("数据库没连上");
}
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root", "123456");
String sql="select name,password from user";
Statement st=con.createStatement();
ResultSet rs=st.executeQuery(sql);
if(rs.next()){
//System.out.print("hello word");
if(rs.getString("name").equals(name)&& rs.getString("password").equals(pass)){
System.out.print("hello word");
jf.setVisible(false);
new MyFrame();
}
else{
JOptionPane jo=new JOptionPane();
jo.showMessageDialog(jf, " 用户名密码错误 请 出 新 输 入 ! ", "错 误 提示", JOptionPane.CLOSED_OPTION);
}
}
我把用户名和密码都写正确为什么还是显示用户密码错误的对话框 并且显示2便
rs.close();
}
catch(Exception ex){
System.out.println("数据库没连上");
}
//System.out.print("hello word");
if(rs.getString("name").equals(name)&& rs.getString("password").equals(pass)){
System.out.print("hello word");
jf.setVisible(false);
new MyFrame();
}
直接JOptionPane.showMessageDialog(jf, " 用户名密码错误 请 出 新 输 入 ! ", "错 误 提示", JOptionPane.CLOSED_OPTION);
在比较前都都print出来 你就知道对不对了 很有可能传递出问题了
这建议你用JDBC,直接 连接.