| Author |
jsp resultset
|
Li Jenny
Ranch Hand
Joined: Apr 19, 2010
Posts: 57
|
|
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
Joined: Apr 16, 2010
Posts: 15
|
|
Do you import java.sql.ResultSet in jsp page?
you can talk to me with msn if you need
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14685
|
|
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.
|
[My Blog]
All roads lead to JavaRanch
|
 |
Aaron Liu
Greenhorn
Joined: Apr 16, 2010
Posts: 15
|
|
|
You can attach a screenprint jpg file to this topic for more details.
|
 |
Li Jenny
Ranch Hand
Joined: Apr 19, 2010
Posts: 57
|
|
session.setAttribute("ID",rs.getString("ID"));
javax.servlet.ServletException: java.sql.SQLException: Before start of result set
|
 |
Aaron Liu
Greenhorn
Joined: Apr 16, 2010
Posts: 15
|
|
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
Joined: Apr 19, 2010
Posts: 57
|
|
|
can i get exactly the data of row in the resultset, not everytime is "while(rs.next())"
|
 |
 |
|
|
subject: jsp resultset
|
|
|