Morning all, before anyone says, yes I looked at solutions online to formulate where I could be going wrong, my JSF page works correctly since I tested it myself. But the prime issue is in the login class of java where I can't figure out why when I type a username and password such as "MWR0025" I should be directed to its webpage "Admin_home". Could anyone from the community help point out where I could be going wrong.
So far I tested the SQL script which I've tested to work in MYSQL workbench, same with the connection driver. Here is my source code below where I've commented things out.
public String checkValidUser() {
login(name, password);
if (name.equalsIgnoreCase(dbUname)) {
if (password.equals(dbPword)) {
return "";
} else {
return "";
}
}
return "Admin_home";
}
public void login(String uName, String pWord) {
try {
PreparedStatement ps = null;
Class.forName("com.mysql.jdbc.Driver");
Connection cn = DriverManager.getConnection("jdbc:mysql://localhost:3306/unidb", "root", "");
//Statement st = cn.createStatement();
ps = cn.prepareStatement("Select * from SPAS_Login_Details where Username = MWR0025 and Password = MWR0025");
ps.setString(1, uName);
ps.setString(2, pWord);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
System.out.println("Works");
}
//String SQL = "Select * from SPAS_Login_Details where Username = ? and Password = ?";
//SQL = "select * from `SPAS_Login_Details` where Username like ('" + uName +"')";
//PreparedStatement PS = cn.prepareStatement(SQL);
//ResultSet Rset = PS.executeQuery();
//Rset.next();
//dbUname = Rset.getString(1);
} catch (Exception ex) {
ex.printStackTrace();
System.out.println("Error has occured:");
}
}
Aucun commentaire:
Enregistrer un commentaire