I am building a web application that has a login page (
jsp) and that attempts to check the user credentials by connecting to and searching for the username from a
java db database. I use javabeans to initialize the form data and then call a function to validate the user.
The function works perfectly outside of the jsp file, but keeps giving a NullPoiunterException when called from the jsp.
Within the jsp, i issue the command:
<% if(loginHandler.validate(); %>
The class associated with the bean (loginHandler) is listed below:
public class VerifyLogin{
private
String username;
private String password;
private String userDB;
private java.sql.Connection user_conn;
private String query_string;
private java.sql.Statement user_statement;
private java.sql.ResultSet user_credentials;
public VerifyLogin(){
username = null;
password = null;
userDB = null;
user_conn = null;
query_string = null;
user_statement = null;
user_credentials = null;
}
public String getUsername(){
return username;
}
public String getPassword(){
return password;
}
public void setPassword(String pw){
this.password = pw;
}
public void setUsername(String un){
this.username = un;
}
public boolean validate() throws java.sql.SQLException{
boolean valid_user = false;
userDB = "jdbc:derby://localhost:1527/OfficeAppsDB;user=admin;password=Passw0rd";
query_string = "SELECT * FROM ADMIN.USERS";
try{
Class.forName("org.apache.derby.jdbc.ClientDriver");
user_conn = java.sql.DriverManager.getConnection(userDB);
}
catch(java.sql.SQLException ex){
ex.printStackTrace();
}
catch (java.lang.Exception ex){
ex.printStackTrace();
}
try{
user_statement = user_conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_SENSITIVE, java.sql.ResultSet.CONCUR_READ_ONLY);
user_credentials = user_statement.executeQuery(query_string);
}
catch (java.sql.SQLException ex) {
ex.printStackTrace();
}
if(user_credentials.next()){
if(user_credentials.getObject("username").equals("paebanks")){
valid_user = true;
}
}
user_statement.close();
user_conn.close();
return valid_user;
}
}
The offending statement seems to be:
user_statement = user_conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_SENSITIVE, java.sql.ResultSet.CONCUR_READ_ONLY);
This class works perfectly in a static context (from main), but keeps giving the exception when called from the jsp file. Can anyone shed some light on this?
[ March 20, 2008: Message edited by: Princeton Ebanks ]