• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

ResultSet Traverse Problem...please help

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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("jdbc:odbc:omah");
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("jdbc:odbc:omah");
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
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!