| Author |
simple doubt but getting headache
|
yerra reddy gatla
Greenhorn
Joined: Apr 25, 2006
Posts: 25
|
|
Hi Everybody I am writing a jsp to search for the existing record with the email id. If the user enters email and press search button it goes to a servlet whose looks like.. ____________________________________________________________________________ String email=req.getParameter("email"); ........... ....... ......... ResultSet rs=stmt1.executeQuery(" select * from vendorinfo where email='"+email+"' "); if(rs.next()) { session.setAttribute("RS",rs); } RequestDispatcher rd=sctxt.getRequestDispatcher("/VendorForm.jsp"); rd.forward(req,resp); ___________________________________________________________________________ My problem is if the entered email is already there in the databse,It is displaying the form with corresponding values.. no probs with this. But when we enter a new mail-id,it should not go into the if(rs.next()) and there wil be no result set in the sesion. Then I can display page with blank fileds means new form....... But it is entering into if condition in the above code even there is no record with the mail-id entered..... I think query is correct ,I am not getting where the problem is.......... Hope it clarifies my doubt Can anybody clarify it.. any help will be appreciable.. Regards gyreddy Trying to breath java..
|
 |
yerra reddy gatla
Greenhorn
Joined: Apr 25, 2006
Posts: 25
|
|
In jsp I am writing rs.getXXX() methods. If it is new mail id also it is entering into if condition in the above given java code. and putting some value in session. In jsp, when it comes rs.getXXX() method it is saying INVALID CURSOR STATE because no record exists with that mail id. It is unable get the values.. My problem wil be clear if it doesn't enter into if condition in Java program(shown in above query). Can anybody trace it.?
|
 |
Ben Souther
Sheriff
Joined: Dec 11, 2004
Posts: 13410
|
|
|
Moving to the JDBC forum where the database gurus hang out.
|
Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
|
 |
Richard Green
Ranch Hand
Joined: Aug 25, 2005
Posts: 536
|
|
First of all, dont pass in resultset to a view (JSP), its bad pratice. Do something like this instead. Now in your vendorform.jsp, get the "emailSet" request attribute out and loop through the set and display the results. if it is empty then display a form that has blank fields.
|
MCSD, SCJP, SCWCD, SCBCD, SCJD (in progress - URLybird 1.2.1)
|
 |
Richard Green
Ranch Hand
Joined: Aug 25, 2005
Posts: 536
|
|
I can see what went wrong with your code: You did a search that returned some records. The resultset was stored in the session. You came back to the page and did another search. This search did not return any records, BUT the attribute "RS" still exists in your session. But the recordset is an invalid state now, therefore you get the "INVALID CURSOR STATE" exception when you goto the JSP. Makes sense? [ June 28, 2006: Message edited by: Lynette Dawson ]
|
 |
 |
|
|
subject: simple doubt but getting headache
|
|
|