Problem with User / Password page

I have a form that gets processed by a javabean.

I am checking the userName and Password to a mysql database and my check always invokes a null value. Please Help me... Below is the javaBean code

This if very urgent......please 500 points

// Java FormBean.java
//This checks the inputs from the user screen
package crm.formprocess;
import java.util.*;
import java.sql.*;

public class FormBean {
      String userName = "";
      String password = "";
      Hashtable errors;
      String errorChecking = "go";
      String userCheck;
      String passwordCheck;
      String errorMsg;

  /**
   * Run the query.
   */
  public void runQuery()
    throws Exception
  {

    /* Use JDBC to connect to the SAMPLE database.*/
    Class.forName("org.gjt.mm.mysql.Driver");
      Connection dbConn = DriverManager.getConnection("jdbc:mysql://localhost:3306/crm", "root", "password");

    /* If the connection fails, throw an Exception.*/
    if(dbConn == null)
    {
      throw new Exception("The database connection failed.");
    }

    /* Build a SQL SELECT statement.*/
    String sqlSelect = "SELECT user, Password FROM users WHERE user='"+ userName;

    /* Run the SELECT statement.*/

    Statement statement = dbConn.createStatement();
    ResultSet result = statement.executeQuery(sqlSelect);

    /* Get the result row.*/
        while(result.next())
    {
      userCheck = result.getString("user");
      passwordCheck = result.getString("Password");
    }

    /* Close the connection.*/
    dbConn.close();
  }
public boolean validate () {
      boolean allOK = true;
      if(errorChecking.equals("No")) {
            errorMsg = "Error in System";
            allOK=false;
      } else if (!(password.equals(passwordCheck))) {
            errorMsg = "Username and/or Password incorrect";
            allOK=false;
      } else if (!(userName.equals(userCheck))) {
            errorMsg = "Username and/or Password incorrect";
            allOK=false;
      }
      return allOK;
}

public String getErrorMsg(String s) {
      String errorMsg = (String)errors.get(s.trim());
      return (errorMsg == null) ? "":errorMsg;
}


public String getUserName() {
      return userName;
}

public String getPassword() {
      return password;
}
public String getErrorMsg() {
      return errorMsg;
}
public String getUserCheck() {
      return userCheck;
}
public String getPasswordCheck() {
      return passwordCheck;

}
public void setUserCheck(String value) {
      userCheck = value;
}

public void setUserName(String value) {
      userName = value;
}

public void setPassword(String value) {
      password = value;
}

}
jr_hanesAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jr_hanesAuthor Commented:
This is the controller

<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="java.util.*" %>


<jsp:useBean id="formHandler" class="crm.formprocess.FormBean" scope="request">
      <jsp:setProperty name="formHandler" property="*"/>
</jsp:useBean>




<%
      if (formHandler.validate()) {
%>
      <jsp:forward page="contacts.jsp?ID=2"/>
<%
      } else {
%>
      <jsp:forward page="index.jsp"/>
<%
      }
%>
0
bloodredsunCommented:
>>my check always invokes a null value.

It would be helpful if you actually posted the exception or null ouput rather than decribing it yourself: do you mean a value equals null or a NullPointerException and if a value is null which value.

Firstly I would suspect your malformed sql statement
  String sqlSelect = "SELECT user, Password FROM users WHERE user='"+ userName;
should be this (you forgot the final sinlge quote around the String userName)
  String sqlSelect = "SELECT user, Password FROM users WHERE user='"+ userName +"'";

You should also check a number of things: the capitalisation of your parameters and variables (and column names), whether you need to use equalsIgnoreCase() rather than equals() etc
0
jr_hanesAuthor Commented:
while(result.next())
    {
      userCheck = result.getString("user");
      passwordCheck = result.getString("Password");
    }

it returns a null for userCheck and passwordCheck
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

jr_hanesAuthor Commented:
I do NOT get error messages when i compile and no error messages when i run it from a browser.

It just doesn't seem like it is matching up my form and my query.
0
Manikandan ThiagarajanSenior consultantCommented:
check your connection string that would be connected to table.

check your table name
0
radarshCommented:
It just means that your query hasn't returned any results. Check the query by putting
single quotes as bloodredsun said and also try putting a print statement in the while
loop and see if you get any iterations. I think it is not at all entering the while
loop.

One more point. What is the value of userName you pass to the query? Is it a valid one
or, by any chance, is it an empty string? Check that also by printing.

________
radarsh
0
fargoCommented:
Hi,

I don't see where is the runQuery() method of FormBean class is called to retrieve the results from the database?
If not called, the userCheck and passwordCheck is never populated and so gives null.

regards,
fargo
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jr_hanesAuthor Commented:
Oops. I didn't run the runQuery() method from the jsp page. Thanks
0
fargoCommented:
Hi,

i think bloodredsun should be a part of split. He helped you fix one of the sql query.

fargo
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.