File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Android Security Essentials Live Lessons this week in the Android 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())"
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: jsp resultset
 
Similar Threads
unique session for every tabs of browser window
Convert int to String using jstl tags
Getting error while adding rows
Basic question about a sql select
Session ID