How to make the previous buttons and next buttons?

i have a table in the database.

There is a page with three buttons Retrieve, Previous and Next as well as as text fields where the data retrieved does appear.

Once i click on theretrieve button it retrieves a row of information onto the text fields.

I want to be able to move to the previous or next rows on the table and display the information by clicking on the previous or next buttons. At the moment the previous and next buttons does work they throwNullPointerException. only the retrieve button works.

how should i proceed?

below is my code for the three buttons

publicvoid actionPerformed(ActionEvent ae)

{

if(ae.getSource().equals(jbtnRt))

{

try{

rtr ="Select * from Employees";

ResultSet rs = stmt.executeQuery(rtr);

if(rs.next())

{

jFirstName.setText(rs.getString(1));

jSurname.setText(rs.getString(2));

jCity.setText(rs.getString(3));

jCountry.setText(rs.getString(4));

jSSN.setText(rs.getString(5));

}

}

catch(SQLException ce)

{

System.out.println(ce);

}

}

if(ae.getSource().equals(jbtnPrv))

{

try

{

if(rs.previous())

{

jFirstName.setText(rs.getString(1));

jSurname.setText(rs.getString(2));

jCity.setText(rs.getString(3));

jCountry.setText(rs.getString(4));

jSSN.setText(rs.getString(5));

}

else

{

JOptionPane.showMessageDialog(this,"No Records","Database

Error Message", JOptionPane.ERROR_MESSAGE);

rs.first();

}

}

catch(SQLException ce)

{

System.out.println(ce);

}

}

if(ae.getSource().equals(jbtnNt))

{

try

{

if(rs.next())

{

jFirstName.setText(rs.getString(1));

jSurname.setText(rs.getString(2));

jCity.setText(rs.getString(3));

jCountry.setText(rs.getString(4));

jSSN.setText(rs.getString(5));

}

else

{

JOptionPane.showMessageDialog(this,"No Records","Database

Error Message", JOptionPane.ERROR_MESSAGE);

}rs.last();

}

catch(SQLException ce)

{

System.out.println(ce);

}

}

}

any idea how to proceed?

[3783 byte] By [bakesa] at [2007-11-27 9:03:09]
# 1

on the startup of your application, retrieve all the db data and store them into a collection (a java.util.ArrayList for example). when hitting a previous or a next button, you have to select the current row (a bean I presume).

NB:

1 - when you reach the first element of your arraylist disable the previous button

2 - when you reach the last recored, disable the next button

3 - enable both buttons otherwise

hope that helps

java_2006a at 2007-7-12 21:34:50 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...