java swing失败认证

时间:2015-02-17 19:19:50

标签: java sql swing

大家好,我正在Netbeans上开发一个java Swing应用程序 在这个块中,当我尝试使用SQL请求使用登录名和密码进行身份验证时,我遇到了一些问题 问题是每次我都会发现SQL异常消息:“erreur gerant”

    if (user.getText().equals("root") & pwd.getText().equals("rootouss")) {

        admindao.sauthentifier(ad) ;
        EspaceGerant eg = new EspaceGerant();
        JOptionPane.showMessageDialog(null,"Bienvenue Administrateur");
        eg.setVisible(true);
        dispose();


    } else if("root" != user.getText()  & "rootouss" != pwd.getText()){
            String sqlGerant ="Select * from gerant where login=?,password=?";
        try {

            PreparedStatement pst= conn.prepareStatement(sqlGerant);
            pst.setString(1, user.getText());
            pst.setString(2, pwd.getText());
            rs=pst.executeQuery();

            if(rs.next()){
                 JOptionPane.showMessageDialog(null,"Bienvenue Gerant");
                 GerantBundle gerBun = new GerantBundle();
                 gerBun.setVisible(true);
                 dispose();
            }

        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null,"erreur Gerant ");
        }

    }

1 个答案:

答案 0 :(得分:1)

您的SQL语句语法不正确:

Select * from gerant where login=?,password=?

应该是:

Select * from gerant where login=? AND password=?