0

hi everyone i'm developping a java Swing application on Netbeans in this block i have some issues when i try to authentify with login and password using an SQL request the problem is that everytime i reveive the SQL exception message :"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 ");
        }

    }
4
  • Please show the stack trace - for this you can add ex.printStackTrace() into your catch block. Commented Feb 17, 2015 at 19:26
  • sorry for the sql SELECT : i have to change it ( it's updated now) yes when i put ex.printStackTrace(); : com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'password='admin'' at line 1 Commented Feb 17, 2015 at 19:30
  • ""root" != user.getText()" is not how Strings are compared in Java, you should be using ".equals" Commented Feb 17, 2015 at 20:40
  • oh yes there's some doubt about this but it works fine :) thanks Commented Feb 17, 2015 at 20:46

1 Answer 1

1

Your SQL statement syntax is incorrect:

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

should be:

Select * from gerant where login=? AND password=?
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.