Hi,
I'm kind of new in Java and trying to get a DB connection through JSP pages.
I'm using Derby as DB since MySQL won't install correctly.
Below is my login_bean which I use to compare what a user types in the login boxes to what's in DB, but something is not correct since I only get "Incorrect Username or Password!!" as message. That message is created on the login_fail.jsp page which it goes to when checkValidUser() returns "invalid"
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package beans; import javax.faces.bean.ManagedBean; import javax.faces.bean.RequestScoped; import java.sql.*; import java.util.*; /** * * @author kdehouwer */ @ManagedBean(name="login_bean") @RequestScoped public class login_bean { private String username; private String password; private String dbusername; public String getDbpassword(){ return dbpassword; } public String getDbusername(){ return dbusername; } private String dbpassword; Connection con; ResultSet rs; public void dbData(String UName){ try{ Class.forName("org.apache.derby.jdbc.ClientDriver"); con = DriverManager.getConnection("jdbc:derby://localhost:1527/recommendation"); PreparedStatement statement = con.prepareStatement("SELECT * FROM users WHERE username like ('" + UName + "')"); rs = statement.executeQuery(); rs.next(); dbusername = rs.getString(2).toString(); dbpassword = rs.getString(3).toString(); } catch(Exception ex){ ex.printStackTrace(); System.out.println("Exception Occur: " + ex); } } public String getPassword(){ return password; } public void setPassword(String password){ this.password = password; } public String getUsername(){ return username; } public void setUsername(String username){ this.username = username; } public String checkValidUser(){ dbData(username); if(username.equalsIgnoreCase(dbusername)){ if(password.equals(dbpassword)){ return "valid"; }else{ return "invalid"; } }else{ return "invalid"; } } /** Creates a new instance of login_bean */ public login_bean() { } }