[英]Jtable values duplicating the last value
Im developing java desktop application for my college assignment. 我为我的大学任务开发java桌面应用程序。 I have encounter a problem while i'm loading values to the Jtable.
我在将值加载到Jtable时遇到了问题。 I used following code to load values.
我使用以下代码来加载值。 It makes duplicate entries.
它会重复输入。 Can you please help me to get rid of this issue?
能帮我摆脱这个问题吗?
private void LoadSupplierTable() {
clearTable((javax.swing.table.DefaultTableModel) tblSupp.getModel());
javax.swing.table.DefaultTableModel dtSupp = (javax.swing.table.DefaultTableModel) tblSupp.getModel();
Vector ver = new Vector();
try {
ResultSet resO = null;
String sqo = "select id,name from supplier";
Connection coo = DataBaseConnection.getDbConnection();
PreparedStatement pso = coo.prepareStatement(sqo);
resO = pso.executeQuery();
while (resO.next()) {
ver.add(resO.getInt("id"));
ver.add(resO.getString("name"));
dtSupp.addRow(ver);
}
} catch (Exception e) {
e.printStackTrace();
}
}
You should declare the vector inside the while loop... just copy paste the following code 你应该在while循环中声明向量...只需复制粘贴以下代码
private void LoadSupplierTable() {
clearTable((javax.swing.table.DefaultTableModel) tblSupp.getModel());
javax.swing.table.DefaultTableModel dtSupp = (javax.swing.table.DefaultTableModel) tblSupp.getModel();
try {
ResultSet resO = null;
String sqo = "select id,name from supplier";
Connection coo = DataBaseConnection.getDbConnection();
PreparedStatement pso = coo.prepareStatement(sqo);
resO = pso.executeQuery();
while (resO.next()) {
Vector ver = new Vector();
ver.add(resO.getInt("id"));
ver.add(resO.getString("name"));
dtSupp.addRow(ver);
}
} catch (Exception e) {
e.printStackTrace();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.