Results 1 to 4 of 4
Like Tree2Likes
  • 1 Post By Tolls
  • 1 Post By doWhile

Thread: JDBC_Servlet: Data not found

  1. #1
    mithcool is offline Member
    Join Date
    Jun 2011
    Posts
    5
    Rep Power
    0

    Default JDBC_Servlet: Data not found

    There is some problem when i check username and validate it against password from the database.After checking password from request.getParamter() and validating it against password column from the database it should say "You have been successfully login"... Perhaps I am getting my own else block message"Incorrect Password..." which means there is some problem with the password thing. Here is my servlet code
    XML Code:
     response.setContentType("text/html");
            PrintWriter out= response.getWriter();
            String uname= request.getParameter("txtuname");
            String pass= request.getParameter("txtpass");
            Connection con =null;
            try {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                con=DriverManager.getConnection("jdbc:odbc:SQL","sa","mith1234");
                String select="select Password from sign_up where U_Name=\'"+uname+"\'";
                Statement st= con.createStatement();
                ResultSet rs= st.executeQuery(select);
                if(rs.next())
                {
                    //out.println(pass);
                    //out.println(rs.getString(1));
                    if(rs.getString(1).equals(pass))
                    {
                        out.println("You have been successfully logged in"+uname);
                    }
                   else 
                    {
                        out.println("Incorrect Password");
                    }
                }
            }
            catch(Exception e)
            {
                out.println(e);
            }
     
        }
    When i say out.println(rs.getString(1)) it is returning me the data from the database.... Any kind of help appreciated!!!!

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,086
    Rep Power
    20

    Default

    First off, print out everything. Not just the password from the db (though see below about that) but the pass variable as well.
    Stick marker prefix and suffixes on these printouts so you can see whether there is any extra whitespace.

    Now, this should all be a single SQL statement. There should be no need to check the password at all in Java.
    Also that query should be a PreparedStatement.
    SO:
    Java Code:
    SELECT 1 FROM sign_up WHERE U_Name = ? AND password = ?
    Then, if rs.next() is true you know that the username and password are valid. No need to let the password out of the database at all.
    mithcool likes this.

  3. #3
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default

    mithcool likes this.

  4. #4
    mithcool is offline Member
    Join Date
    Jun 2011
    Posts
    5
    Rep Power
    0

    Default

    thanks a lot friend... It is working perfectly fine n sorry for cross posting.... I wont cross post again.... thanks again...
    Just a question: Now I also want to check whether the username is already there in the database which i can check through rs.getString() but i just want to through some javacript message for that. So how can i let javacript which is a client side scripting communicate with my servlet code???

Similar Threads

  1. SQLException caught:No data found
    By jttslg in forum Java Servlet
    Replies: 20
    Last Post: 05-20-2011, 05:21 PM
  2. SQLException caught:No data found
    By jttslg in forum NetBeans
    Replies: 0
    Last Post: 04-20-2011, 04:07 PM
  3. JAD NOT FOUND !! hlp
    By ganero in forum CLDC and MIDP
    Replies: 1
    Last Post: 01-17-2011, 05:09 AM
  4. data.txt not found
    By RedSix in forum Eclipse
    Replies: 4
    Last Post: 04-23-2009, 02:43 AM
  5. 404 Not Found
    By mary in forum Java Servlet
    Replies: 5
    Last Post: 11-07-2007, 10:15 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •