aspose file tools*
The moose likes JDBC and the fly likes jsp Login Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "jsp Login" Watch "jsp Login" New topic
Author

jsp Login

Reuben Fields
Greenhorn

Joined: Apr 05, 2005
Posts: 15
hi guys,

im tryin to get a login working in jsp but it doesnt seem to be accessing the while loop...

any ideas on how i can get this working?

<%

Class.forName("org.gjt.mm.mysql.Driver");
String strUrl = "jdbc:mysql://localhost/broadweb";
Connection conn=DriverManager.getConnection (strUrl,"root","321321");

Statement stmt=conn.createStatement();

// Get Parameters
String login_name = request.getParameter("login_name");
String password = request.getParameter("password");

// Query String
String strSQL = "SELECT person_type FROM person WHERE login_name = '" + login_name + "' AND password = '" + password + "'";

// Execute
ResultSet result = stmt.executeQuery(strSQL);
while (result.next())
{
String person_type = result.getString(1);
if (person_type.equals("member"))
{
HttpSession currSession = request.getSession(true);
currSession.putValue("priv", "1");
//String storedName = currSession.getValue("userName");

out.print("Member\n\n");
}
else if (person_type.equals("admin"))
{
HttpSession currSession = request.getSession(true);
currSession.putValue("priv", "2");

out.print("Administrator\n\n");
}
else
{
out.print("Error - Invalid Type\n\n");
}

}

// Close
stmt.close();
conn.close();

%>
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
im tryin to get a login working in jsp but it doesnt seem to be accessing the while loop...


It probably means your query

did not return any matches.

I would verify that the login/password exists in your table.
Reuben Fields
Greenhorn

Joined: Apr 05, 2005
Posts: 15
Yeah i have the info in my database so i dont know why its not working
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

does the query result on sql console if yes then

<%=strSQL %> what is out put of this ? and did you try printing the query on jsp and executing same.

what if login_name or password is null ???

Shailesh


Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
I personally, cannot see anything wrong with the syntax of your code. So assuming you are not getting any errors, I would again suggest you verify that the data values are correct.

Have you verified that the following is returning valid data and the syntax of the url is correct:
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
Oh, and one more thing. If you are not sending the login_name and password values as part of the url, which is something I recommend.

And if you are using the "POST" method(for example a Form submit) to forward the data in the request object, you will need to access your data by using the following getAttribute methods of the SerlvetRequest Interface instead of the getParameter methods:

 
 
subject: jsp Login