List:General Discussion« Previous MessageNext Message »
From:Jonathan Howells Date:April 10 2000 11:32am
Subject:Problem testing Null Values
View as plain text  
Can anyone help with this Java Servlet querying a null
value?

We are making a login page for a website with a MySQL
database and have the following loop which checks if
the username and password is already there or not.  It
works if they are but if not it just prints a blank
screen.  We are using JDK 2 on Tomcat servlet runner
and it does not seem to like the null value.  Is this
a Java problem, how can we test for nulls from the
database.

Thanks for your help, sorry if this is not a database
problem.
Jon     

   //run this sql query
        rs = stmt.executeQuery ("SELECT firstname,
username , password FROM member where username =  '" +
username +"' AND password = '"+password+"'");

        //dISPLAY THE SQL RESULTS
       

//{
//Object user= rs.getObject("username"));
//if (!rs.wasNull())
//out.println("sorry" + user);
//}  


out.println("<html>");
 
      
        while(rs.next())
        {
String user;
String pass;
if (rs.wasNull()){
user = "no user name";
pass = "no password"; }
else {
user = rs.getString("username");
pass = rs.getString("password");  
}   



out.println(pass.trim() + ", " + user.trim());


}
out.println("</body></html>");

}

____________________________________________________________
Do You Yahoo!?
Get your free @yahoo.co.uk address at http://mail.yahoo.co.uk
or your free @yahoo.ie address at http://mail.yahoo.ie
Thread
Problem testing Null ValuesJonathan Howells10 Apr
  • Re: Problem testing Null ValuesChristian Mack18 Apr