I am using the code below to display the records from my database in the swing form. However, when I click on the button it only shows the first record of the database (table in database has 5 records)
private void btnnextActionPerformed(java.awt.event.ActionEvent evt) {
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:StudentDetails");
Statement stm=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rs=stm.executeQuery("Select * from NurseryStDetails");
if(rs.first())
{
txtstID.setText(rs.getString(1));
txtname.setText(rs.getString(2));
txtaddress.setText(rs.getString(3));
// int i=rs.getInt(4);
// String s=String.valueOf(i);
// txtage.setText(rs.getString(s));
// int j=rs.getInt(5);
// String t=String.valueOf(j);
txtage.setText(rs.getString(4));
txttelephone.setText(rs.getString(5));
txtgNIC.setText(rs.getString(6));
txtgname.setText(rs.getString(7));
}
}
catch(Exception ex)
{
System.out.println("Exception caught"+ex);
}
}
is it
if(rs.first()) ??
try
while (rs.next())
This will help u to iterate through the resultset.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With