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("数据库没连上");
}

解决方案 »

  1.   

    if(rs.next()){ ==>觉得要改成while,其它的我不清楚
    //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(); 
    }
      

  2.   

    去掉JOptionPane jo=new JOptionPane(); 
    直接JOptionPane.showMessageDialog(jf, "  用户名密码错误 请 出 新 输 入 ! ", "错 误 提示", JOptionPane.CLOSED_OPTION); 
      

  3.   

    这样看了下 程序没什么问题.为什么不把用户名和密码
    在比较前都都print出来 你就知道对不对了 很有可能传递出问题了
      

  4.   

    看看数据库user表中 name 和 password 是不是有多个数据行
      

  5.   

    这样写法不规范,这是用的ODBC这个技术不是很好.
        这建议你用JDBC,直接 连接.