wood burning stoves 2.0*
The moose likes Servlets and the fly likes Urrgent Pls Advice as soon as possible Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Urrgent Pls Advice as soon as possible" Watch "Urrgent Pls Advice as soon as possible" New topic
Author

Urrgent Pls Advice as soon as possible

vikram nalagampalli
Ranch Hand

Joined: Oct 08, 2001
Posts: 91
I am having probelms in using session.putValue and getValue
I am authorizing the users with their username and password. Once it is sucessful i am forwarding the user to a Welcome.jsp page.
I am trying to put the userId information in the LoginHandler.jsp page with the help of session.putValue() and am trying to retreive it from Welcome.jsp page through session.getValue().
But i am facing an error "Invalid cursor state"
What does this mean. I want to know what could be worn in this.I am also sending u the code for both the pages
LoginHandler.jsp
<%@ page session="true" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.lang.String" %>
<%
String userId = request.getParameter("userId");
String password = request.getParameter("password");
%>
<%String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String url = "jdbc dbc:Resume";
Class.forName(driver);
Connection con=null;
try{
con=DriverManager.getConnection(url);
String query="SELECT * FROM Password "
+"WHERE Ssn ="+userId+" AND Password='"+password+"'";
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(query);
String query1="SELECT Ssn FROM Profile WHERE Ssn ="+userId;
Statement stmt1=con.createStatement();
ResultSet rs1=stmt1.executeQuery(query1);
if (rs.next()){
session.putValue("login",userId);
if (rs1.next()){
%>
<jsp:forward page="Welcome.jsp"/>
<% }else{ %>
<jsp:forward page="profile.html"/>
<% } %>
<% }else{ %>
<jsp:forward page="Login.jsp"/>
<%
}
rs.close();
rs=null;
rs1.close();
rs1=null;
stmt.close();
stmt=null;
stmt1.close();
stmt1=null;
}
finally{
if(con!=null){
con.close();}
}
%>

Welcome.jsp
<%
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String url = "jdbc dbc:Resume";
Class.forName(driver);
Connection con=null;
String userId = (String)session.getValue("login");
try{
con=DriverManager.getConnection(url);
String query="SELECT LastName, FirstName FROM Profile WHERE Ssn="+userId;
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(query);
%>
<b>Welcome<%= rs.getString("FirstName") %> <%=rs.getString("LastName") %>
<%
rs.close();
rs=null;
stmt.close();
stmt=null;
}
finally{
if(con!=null){
con.close();}
}
%>
</BODY></HTML>
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

session.putValue() and session.getValue(String) are deprecated as of Servlet 2.2
-- they have been replaced by session.setAttribute() and session.getAttribute(String)
Try using those and see if that helps.


- Jess
Blog:KnitClimbJava | Twitter: jsant | Ravelry: wingedsheep
Abraham Jacob
Greenhorn

Joined: Oct 16, 2001
Posts: 25
I am not sure if this is the answer.. but it could well be..
In welcome.jsp (u have written) ----
ResultSet rs=stmt.executeQuery(query);
%>
<b>Welcome<%= rs.getString("FirstName") %> <%=rs.getString("LastName") %>
<%
----------
just after opening the resultset u have not used
rs.next()
rs.next() does 2 things
1) Returns a boolean which tells you whether it a record exist in the cursor
2) It advances the cursor pointer to the next record.
Just after getting the resultset the pointer is before the first record in the resultset and hence I think therein lies ur problem...
vikram nalagampalli
Ranch Hand

Joined: Oct 08, 2001
Posts: 91
I tried using the setAttribute() and getAttribute() and i am still encountering with the same error "Invalid Cursor State"
Can somebody figure out what is worng.
Regads and thanks
vikram

Originally posted by Jessica Bradley:
session.putValue() and session.getValue(String) are deprecated as of Servlet 2.2
-- they have been replaced by session.setAttribute() and session.getAttribute(String)
Try using those and see if that helps.

vikram nalagampalli
Ranch Hand

Joined: Oct 08, 2001
Posts: 91
Thanks a lot abraham,
It solved my problem.
Regards,
vikram

Originally posted by Abraham Jacob:
I am not sure if this is the answer.. but it could well be..
In welcome.jsp (u have written) ----
ResultSet rs=stmt.executeQuery(query);
%>
<b>Welcome<%= rs.getString("FirstName") %> <%=rs.getString("LastName") %>
<%
----------
just after opening the resultset u have not used
rs.next()
rs.next() does 2 things
1) Returns a boolean which tells you whether it a record exist in the cursor
2) It advances the cursor pointer to the next record.
Just after getting the resultset the pointer is before the first record in the resultset and hence I think therein lies ur problem...

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Urrgent Pls Advice as soon as possible
 
Similar Threads
multiple processes... only want one
Some one help me pLSSSSSSSSSSSsssssss
Problem integrating Input box with JSP
Need Help with check box values!
JDBC Error (Missing Operator)