This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ResultSet Traverse Problem...please help

 
omar salem
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("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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic