when i press the button it always duplicate the existing records on the jTable

Mark Mark :

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);
    }
}
am0awad :

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())";

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=349551&siteId=1