0

Whenever I press log-in it shows the catch message.

tried setting it to ResultSet.getString(name of column in access).equal(value of textfield)

b1.addActionListener(new ActionListener () 
        {

            public void actionPerformed(ActionEvent e) 
            {
                try
                {
                    String u1=t1.getText();
                    String u2=t2.getText();

                    if (u1==rs.getString("Name") || u2==rs.getString("Pass"))
                    {
                    JOptionPane.showMessageDialog(null, "Success");
                    }
                }
                catch (Exception ex)
                {
                    JOptionPane.showMessageDialog(null, "Invalid");
                }
            }
        });

It always shows catch message which is "Invalid". Also I am using Ucanaccess for my program to connect with MS access.

theduck
  • 2,589
  • 13
  • 17
  • 23

1 Answers1

0

String comparison should be done using the equals method

  if (u1.equals(rs.getString("Name")) || u2.equals(rs.getString("Pass")) {

Edit:

Also, add ex.printStackTrace(); in your code in case there is an issue

catch (Exception ex)
  {
    ex.printStackTrace();   
   JOptionPane.showMessageDialog(null, "Invalid");
  }

Just assuming you comparing user name and password, in this case, you should use && instead of ||

Shailesh Chandra
  • 2,164
  • 2
  • 17
  • 25
  • Thanks responding but it still returns Invalid –  Oct 12 '19 at 11:17
  • put ex.printStackTrace(); in your code, as mentioned in the edit section, there seems some issue in your code, most likely issue with resultset – Shailesh Chandra Oct 12 '19 at 11:24
  • Thank you when I added ex.printStackTrace(); error showed that my ResultSet was set before the first row so there was nothing to compare it to. –  Oct 12 '19 at 11:33