• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

simple doubt but getting headache

 
yerra reddy gatla
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to the JDBC forum where the database gurus hang out.
 
Richard Green
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Richard Green
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic