Results 1 to 4 of 4
Thread: JDBC_Servlet: Data not found
- 06-24-2011, 05:39 AM #1
Member
- Join Date
- Jun 2011
- Posts
- 5
- Rep Power
- 0
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
When i say out.println(rs.getString(1)) it is returning me the data from the database.... Any kind of help appreciated!!!!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); } }
- 06-24-2011, 10:09 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
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:
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.Java Code:SELECT 1 FROM sign_up WHERE U_Name = ? AND password = ?
- 06-24-2011, 03:47 PM #3
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,608
- Rep Power
- 5
Cross posted at JDBC_Servlet: Data not found
- 06-24-2011, 06:32 PM #4
Member
- Join Date
- Jun 2011
- Posts
- 5
- Rep Power
- 0
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
-
SQLException caught:No data found
By jttslg in forum Java ServletReplies: 20Last Post: 05-20-2011, 05:21 PM -
SQLException caught:No data found
By jttslg in forum NetBeansReplies: 0Last Post: 04-20-2011, 04:07 PM -
JAD NOT FOUND !! hlp
By ganero in forum CLDC and MIDPReplies: 1Last Post: 01-17-2011, 05:09 AM -
data.txt not found
By RedSix in forum EclipseReplies: 4Last Post: 04-23-2009, 02:43 AM -
404 Not Found
By mary in forum Java ServletReplies: 5Last Post: 11-07-2007, 10:15 AM


2Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks