?
Solved

Problem with User / Password page

Posted on 2006-03-24
9
Medium Priority
?
340 Views
Last Modified: 2010-04-01
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;
}

}
0
Comment
Question by:jr_hanes
9 Comments
 

Author Comment

by:jr_hanes
ID: 16285372
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
 
LVL 29

Expert Comment

by:bloodredsun
ID: 16285714
>>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
 

Author Comment

by:jr_hanes
ID: 16285925
while(result.next())
    {
      userCheck = result.getString("user");
      passwordCheck = result.getString("Password");
    }

it returns a null for userCheck and passwordCheck
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:jr_hanes
ID: 16285958
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
 
LVL 9

Expert Comment

by:Manikandan Thiagarajan
ID: 16286873
check your connection string that would be connected to table.

check your table name
0
 
LVL 10

Expert Comment

by:radarsh
ID: 16287062
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
 
LVL 11

Accepted Solution

by:
fargo earned 1500 total points
ID: 16293366
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
 

Author Comment

by:jr_hanes
ID: 16313673
Oops. I didn't run the runQuery() method from the jsp page. Thanks
0
 
LVL 11

Expert Comment

by:fargo
ID: 16313746
Hi,

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

fargo
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
Moore’s Law has proven itself time and time again since it was first introduced. So what’s next? Will Moore’s law continue to remain relevant, or will new technology take over and bring us the next big advancement in computing?
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month16 days, 13 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question