aspose file tools*
The moose likes JDBC and the fly likes ResultSet Traverse Problem...please help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "ResultSet Traverse Problem...please help" Watch "ResultSet Traverse Problem...please help" New topic
Author

ResultSet Traverse Problem...please help

omar salem
Ranch Hand

Joined: Aug 22, 2006
Posts: 34
Hi Ranchers,

I have built a small GUI application using Swing that has one text field and three buttons named first,next,and last respictevely. Using these buttons i want to traverse through the ResultSet object.
when i click on the 'first button' it works fine and retrives the first record from the database.
This is the logic i applied for the 'first' button :
if(ae.getSource()==first)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbcdbcmah");
query = " select * from data1";
st = con.createStatement();
rs = st.executeQuery(query);
while(rs.next())
{
if(rs.getRow()==1)
//System.out.println(rs.getString(1));
t.setText(rs.getString(1));
else
{
while(rs.last())
{
t.setText(rs.getString(1));
}
}

}
}
catch(Exception e)
{
System.out.println(e);
}

now for the 'next' button which will fetch the next record in the database i have read the current cursor position using getRow() method then i increased it by 1 so that the cursor moves to the next record and fetch it then display its value in the text field. Here is the code i applied for this :
if(ae.getSource()==next)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbcdbcmah");
query = " select * from data1";
System.out.println("Hi");
System.out.println("Hi");
st = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs = st.executeQuery(query);
System.out.println("Hi");
int i = rs.getRow();
i = i+1;
System.out.println("Hi");
boolean b = rs.absolute(i);
t.setText(rs.getString(1));

}

catch(Exception e)
{
System.out.println(e);
}
}
i was trying to use the absolute() method but couldnt actually get to the next record. All i need is some help in traversing for first, next, end ad so on.

Regards
Omar Salem


Have a sip of Java !!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ResultSet Traverse Problem...please help
 
Similar Threads
Navigating data using JDBC and SQLServer 2005
jdbc
User Name and Password Verification
Please help me the problem in rs.previous
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid cursor state