Hello,
i am developing a program that will accept a username and a password from a user and compare it with the data stored in a database in Microsoft access if the data received match the data in the database it should then proceed to another screen, but the problem am having is that i created an IF statement that if the entered data is correct it proceeds to the next screen but its also doing that(when input data matches) but its showing that the input was also "invalid" as this was what i place in the code if the username is incorrect so it doing two things at once, is there anyway i can correct this..help would be appreciated
this is my codes below:
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String sourceURL = "jdbc:odbc:KnutsfordDSN";//name of the stored dsn connected to the stored database
Connection con = DriverManager.getConnection(sourceURL);
java.sql.Statement st = con.createStatement();
ResultSet result = st.executeQuery("SELECT*FROM Passwords");//Password table in the database
System.out.println("Connection Made");//if connection was sucessful
while(result.next()){
String Usernames = result.getString("Usernames"); //username column in the password table in the database
String Passwords = result.getString("Passwords");//password column in the password table in the database
if (txtusername.getText().equals(Usernames)&& txtpassword.getText().equals(Passwords)){
Knutsford kd = new Knutsford(); //if usernames and password match this form will be displayed
kd.setVisible(true);
dispose();
}
}if (txtusername.getText().equals("admin") && txtpassword.getText().equals("admin")){
JOptionPane.showMessageDialog(null,"Admin Login");
}else {
JOptionPane.showMessageDialog(null,"Invalid Credentials");
}
}catch(ClassNotFoundException cnfe){
System.err.println(cnfe);
}catch(SQLException ex){
System.err.println("SQLException:"+ex.getMessage());
}//end of making the connection