wood burning stoves*
The moose likes JSP and the fly likes jsp resultset Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "jsp resultset" Watch "jsp resultset" New topic
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: 14687
    
  16

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())"
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jsp resultset
 
Similar Threads
Convert int to String using jstl tags
unique session for every tabs of browser window
Getting error while adding rows
Basic question about a sql select
Session ID