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.
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 ||
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.