java JTable显示相同的项目
正如你所看到的,当我尝试一个新的项目时,得到了这样的重复。我该怎么办
我写了一个JTable
redisplayer类。所以有一个添加按钮到表中。当点击该按钮时,它应该是exp I added 1。在我加2之后。应仅显示1 2。不是那样的
jTable1.removeAll();
jTable1.revalidate();
try{
Class.forName("com.mysql.jdbc.Driver");
}
catch(ClassNotFoundException e){
System.err.println("Driver yok");
return;
}
Connection con=null;
try{
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/kutuphane","root","");
System.out.println("Veritabnı baglandıldı");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("SELECT * FROM kisiler ");
while(rs.next()){
model=(DefaultTableModel) jTable1.getModel();
model.insertRow(i,new Object[]{rs.getString("ADSOYAD"),rs.getInt("TELEFON"),rs.getInt("TCNO"),rs.getString("ADRES") } );
i++;
}
jTable1.setModel(model);
jTable1.revalidate();
stmt.close();
rs.close();
}
catch(SQLException e){
System.out.println("Veritabanı baglanmadi");
e.printStackTrace();
}
finally{
if(con!=null)
try{
con.close();
}
catch(SQLException e){
e.printStackTrace();
}
共 (0) 个答案