This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes how to make a ResultSet  scrollable 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 » Databases » JDBC
Bookmark "how to make a ResultSet  scrollable" Watch "how to make a ResultSet  scrollable" New topic
Author

how to make a ResultSet scrollable

Gayani Kanchana
Greenhorn

Joined: Mar 27, 2007
Posts: 19
Im writing a java web application using net beans 5.5 and SQL server. I want to read same result set twice. therefore i use resultSet.first(). to go to the first record in record set. How ever it throws an exception.
how can I move to first record after i reached end of record set.

Please help.
thanks
krishnamoorthy kitcha
Ranch Hand

Joined: Feb 04, 2006
Posts: 96
Hi Gayani Kanchana ,

First of all you had retrieved all the datas from the result set like

ResultSet rs=ps.executeQuery(sql);
int i=0;
while (rs.next()){
String a =rs.getColumn(i);

}


then

you will try like this

if(rs.last())
{
rs.beforeFirst();

while(rs.next()){

same code
}

}


check and tell me your feedback

Regards,
k.krishnamoorthy.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

Have a look at the API documentation of class java.sql.Connection. There are variants of the methods createStatement(), prepareStatement() and prepareCall() that allow you to specify the result set type. There, you can specify that you need a scrollable result set.

Also, your JDBC driver needs to support scrollable result sets, otherwise it isn't going to work.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to make a ResultSet scrollable
 
Similar Threads
cookies/deleting
File pointers
SQL query????
jdbc
FTP upload