Login System JSF - Identified an SQLException?

Mohammed Rahman :

Well thanks to the people who actually tried helping me but I found out what my problem was in the end: MYSQL script caused it to search for "Admin1" which is my login id when it should have searched username and password so had to modify my query to do so. I'll leave my solution for future apprentices.

    public void dbData(String UName, String PWord) {
    try {
        Class.forName("com.mysql.jdbc.Driver");
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/unidb?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC", "root", "Safia10122014");
        String SQL = "select `Username`, `Password` from `SPAS_Login_Details` where `Username` like 'MWR0025'";

        Statement statement = con.createStatement();

        ResultSet resultSet = statement.executeQuery(SQL);
        resultSet.next();
        dbUname = resultSet.getString(1);
        dbPword = resultSet.getString(2);

    } catch (ClassNotFoundException | SQLException e) {
        e.printStackTrace();
        System.out.println(e);
    }
}

public String validation() {
    dbData(name, password);

    if (name.equalsIgnoreCase(dbUname) && password.equalsIgnoreCase(dbPword)) {
        return "Admin_home";
    } else {
        return "";
    }
}
Mohammed Rahman :

As seen in the edited post:

    public void dbData(String UName, String PWord) {
    try {
        Class.forName("com.mysql.jdbc.Driver");
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/unidb?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC", "root", "Safia10122014");
        String SQL = "select `Username`, `Password` from `SPAS_Login_Details` where `Username` like 'MWR0025'";

        //String SQL = "select * from `SPAS_Login_Details` where `Username` = 'MWR0025' and `Password` = 'MWR0025'";
        //String SQLA = "select * from `SPAS_Login_Details` where `Username` = 'QD0040' and `Password` = 'QD0040'";
        //String SQLB = "select * from `SPAS_Login_Details` where `Username` = 'HB0041' and `Password` = 'HB0041'";
        //String SQLC = "select * from `SPAS_Login_Details` where `Username` = 'VV0042' and `Password` = 'VV0042'";
        //String SQLD = "select * from `SPAS_Login_Details` where `Username` = 'MA0043' and `Password` = 'MA0043'";
        //String SQLE = "select * from `SPAS_Login_Details` where `Username` = 'NF0044' and `Password` = 'NF0044'";

        Statement statement = con.createStatement();

        ResultSet resultSet = statement.executeQuery(SQL);
        resultSet.next();
        dbUname = resultSet.getString(1);
        dbPword = resultSet.getString(2);

    } catch (ClassNotFoundException | SQLException e) {
        e.printStackTrace();
        System.out.println(e);
    }
}

public String validation() {
    dbData(name, password);

    if (name.equalsIgnoreCase(dbUname) && password.equalsIgnoreCase(dbPword)) {
        return "Admin_home";
    } else {
        return "";
    }
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=238666&siteId=1