user1410081
user1410081

Reputation:

JOptionPane isn't showing

JOptionPane is not showing.. Please check my code:

public void actionPerformed(ActionEvent e) {
     // TODO Auto-generated method stub
     //if (e.getActionCommand().equals("Ok")){
     if ( e.getActionCommand().equals(btnOk) ){
              if(connect(txtUser.getText(), txtPass.getText() ) ) {
                  JOptionPane.showMessageDialog(null, "WARNING", "Valid user!", JOptionPane.INFORMATION_MESSAGE);
              }
              else {
                        System.out.print("Wrong password!");
              }

     }
 }

my connect method, please check this.

public boolean connect(String usr, String pwd){

     try {
         Class.forName("com.mysql.jdbc.Driver");
         connection = DriverManager.getConnection(
                     "jdbc:mysql://localhost:3306/USERS", "root", "root" );
          PreparedStatement ps = 
                  connection.prepareStatement( "SELECT lname, fname FROM employees where fname=? and lname =?" );
          ps.setString(1,usr);
          ps.setString(2,pwd);

         resultSet = ps.executeQuery();


       if(resultSet.next()) {
                return true;
       }

     } catch (Exception e) {
         e.printStackTrace();
     }

     return false;
 } // end of connect method

I don't know what's wrong with my code. any help would be appreciated. thanks

Upvotes: 0

Views: 738

Answers (1)

Raul Rene
Raul Rene

Reputation: 10290

If it does not print Wrong password! it means that it does not pass the e.getActionCommand().equals(btnOk) line. Make sure btnOk is a String and it is the String you are looking for.

If it prints Wrong password, it is straighforward why this happens.

btnOk sounds like a button to me, not a String (but without any extra code snippets we just have to guess that), so be careful not to test equality between the String actionCommand and a button.

Upvotes: 2

Related Questions