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
  • 62,771
  • 5
  • 54
  • 92
Mark Mark
  • 7
  • 2

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())";
heaprc
  • 4,395
  • 2
  • 13
  • 26