Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Other Java > Java Databases
| Search | Today's Posts | Mark Forums Read
Java Databases Discussion specific to working with Java Databases. For other Java topics, please see related Java forums. For database discussions not specific to Java, please see the Database category.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old November 23rd, 2004, 04:59 PM
Registered User
 
Join Date: Nov 2004
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default jsp & mysql login code sos

hi all i was hoping that somebody cud help me with my code for my login page. i am very new to jsp as am currently a student but i know that once somebody has corrected my code i will be able to then pick things up.
ok then basicall i hav created a login page and when client side validation is ok the form data gets sent to a login validatation page. i have pasted the code i have done for the validation page below. currently i can successfully connect to the database and execute an sql qry but it is the if structure when i must compare the user entered details to the database details to see if they match
i wud be grateful for the help here
thanks code is below

--------loginvalidation.jsp-------------
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import='java.sql.*, javax.sql.*,javax.naming.*'%>
<html>
<head>
<title>login validator</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<%
Context ic = new InitialContext();
DataSource ds = (DataSource)ic.lookup("java:comp/env/jdbc/test");

Connection conn = ds.getConnection();

try
{
    String user = request.getParameter("txtusername");
    String password = request.getParameter("txtpassword");
    String dbpass = "";

    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("select password from myusers WHERE username = '" + user + "'");

    while(rs.next())
    {
        dbpass = rs.getString(4);
    }
    if (password.equals(dbpass))
        {

        }
    else
        {

        }
}
finally
{
    conn.close();
}

%>


</body>
</html>




  #2 (permalink)  
Old November 24th, 2004, 09:29 AM
Friend of Wrox
 
Join Date: Jul 2004
Location: , , .
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Your if statement looks ok to me, but I am not sure about the SQL.
You are selecting only 'password', but then trying to dbpass = rs.getString(4);

You could try dbpass = rs.getString("password");


Or if you want all strings/field in the recordset available I would use:

select * from myusers WHERE username

you could then use rs.getString(1); rs.getString(2); ... etc


Also you should try writing the value of dbpass to the screen to check its value is correct:

out.println(dbpass);

Remember Java is case sensitive, so make sure you enter password correctly.


  #3 (permalink)  
Old November 24th, 2004, 04:30 PM
Registered User
 
Join Date: Nov 2004
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi thanks for your response
working on mu code last night i had one of those eureka moments and finally cracked it and understood what i was doing
thanks very much for your help


  #4 (permalink)  
Old November 25th, 2004, 05:44 AM
Friend of Wrox
 
Join Date: Jul 2004
Location: , , .
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thats ok, what are you building??

  #5 (permalink)  
Old November 25th, 2004, 06:50 AM
Registered User
 
Join Date: Nov 2004
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi friend
yeah i am new to jsp / mysql but i am trying to build a simple music downloads website. i want to be able to code dynamic webpages. i am using jsp / mysql / and resin as the localhost
thanks



Similar Threads
Thread Thread Starter Forum Replies Last Post
Php code to put&get images from mysql not working! angelbeans PHP Databases 1 September 8th, 2006 12:44 PM
Help! JSP Login yikchin JSP Basics 1 December 8th, 2005 02:35 AM
JSP and LOGIN cbolat JSP Basics 3 November 30th, 2005 04:11 AM
Linux & KDE & C++ & QT & MYSQL & Kdevelop Munnnki Linux 0 January 2nd, 2005 05:41 PM
Help with jsp login page javaStudent JSP Basics 0 January 27th, 2004 06:08 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.