0

When I press the button it always duplicates the existing records on the jTable. How can I show just one data at a time?

void showAll(){
    try{
        rs=stmt.executeQuery("SELECT * FROM ATTENDANCE");
        while (rs.next()){
            String a1 = rs.getString("NAME");
            String b1 = rs.getString("COURSE");
            String c1 = rs.getString("STUDENTNO");
            String d1 = rs.getString("DATE");
            DB1.addRow(new Object[]{a1,b1,c1,d1});
        }
    }catch(Exception e){
        System.out.println(e);
    }
}
Arvind Kumar Avinash
  • 71,965
  • 6
  • 74
  • 110
Mark Mark
  • 17
  • 3

1 Answers1

0

Try this query

String query = "SELECT a.* FROM ATTENDANCE a WHERE id=(SELECT MAX(aa.id) FROM ATTENDANCE aa);"

, or

String query = "SELECT a.* FROM ATTENDANCE a WHERE id=(SELECT LAST_INSERT_ID())";
0xh3xa
  • 4,801
  • 2
  • 14
  • 28