Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp resultset

 
Li Jenny
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when i enter to jsp and call servlet in java session and then return a resultset
afterwards, i get the value of resultset and then pass to session
the code as below

in jsp:
<%
xx a=new object();
ResultSet rs=a.select_user();
String strID=rs.getString("ID");
session.setAttribute("ID",strID);
%>

when i compile the code, there is an error about "record before resultset" somthing like that

how can i fix this???

because i would like to get the value from another jsp by getting session.
 
Aaron Liu
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you import java.sql.ResultSet in jsp page?
you can talk to me with msn if you need
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the ranch !

there is an error about "record before resultset" somthing like that

No, you'll have to be more specific. "something like that" is not going to help us. Please send the exact error that you have.

And also check your private messages.
 
Aaron Liu
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can attach a screenprint jpg file to this topic for more details.
 
Li Jenny
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
session.setAttribute("ID",rs.getString("ID"));

javax.servlet.ServletException: java.sql.SQLException: Before start of result set
 
Aaron Liu
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
before you "result.getXXX", you should call result.next().
see below:
<%
xx a=new object();
ResultSet rs=a.select_user();
if(rs.next()){
String strID=rs.getString("ID");
out.println("strID = " + strId);
session.setAttribute("ID",strID);
}else{
out.println("there is no data in resultset");
}
%>
 
Li Jenny
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can i get exactly the data of row in the resultset, not everytime is "while(rs.next())"
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic