• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Selecting next record from a table

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I have a table with two columns firstname and lastname. I want to display the values in textfields, navigating to next/previous records on pressing 'next' and 'previous' buttons. I am a newbie in jdbc and expecting some advice.

Thanks.
 
Ranch Hand
Posts: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this article will help you to move a head..
 
Shashank Anand
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's a nice one. But I am not using netBeans at present. I am trying to do this with ResultSet. See my code below (that is not working):

ResultSet rs;
Statement stmt;
Connection con;
//Add ActionListeners to Buttons- first,next,previous,last.
public void actionPerformed (ActionEvent e) {
if (e.getActionCommand()=="first") {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con= DriverManager.getConnection("jdbc:odbc:DSNname", "name", "password");
stmt = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
rs=stmt.executeQuery("SELECT firstname, lastname FROM mytable ORDER BY firstname");
while (rs.first()) {
text1.setText(rs.getString(1));
text2.setText(rs.getString(1));
}
con.close();
}
catch (Exception ex) { System.out.println("Error:" + ex); }
}


if (e.getActionCommand()=="next") {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con= DriverManager.getConnection("jdbc:odbc:DSNname", "name", "password");
stmt = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
rs=stmt.executeQuery("SELECT firstname, lastname FROM mytable ORDER BY firstname");
while (rs.next()) {
text1.setText(rs.getString(1));
text2.setText(rs.getString(1));
}
con.close();
}
catch (Exception ex) { System.out.println("Error:" + ex); }
}

...
How can I make it work ?
 
Check your pockets for water buffalo. You might need to use this tiny ad until locate a water buffalo:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic