【发布时间】:2019-09-28 00:51:23
【问题描述】:
我有一个 Java 表格,其中包含几行,但是当我保存数据时,只保存最后一行,其余的不保存。
下面是我的代码:
try {
int rows=jTable1.getRowCount();
for (int row = 0; row < rows; row++) {
String qtys = (String) jTable1.getValueAt(row, 0);
String name = (String) jTable1.getValueAt(row, 1);
String commo = (String) jTable1.getValueAt(row, 2);
String wei = (String) jTable1.getValueAt(row, 3);
String queryco = "Insert into invoice(qtys,name,commo,wei) " +
"values ('"+qtys +"','"+name+"','"+commo+"','"+wei+"')";
pst = conn.prepareStatement(queryco);
pst.execute();
}
JOptionPane.showMessageDialog(null, "Successfully Save");
}
catch (Exception e) {
JOptionPane.showMessageDialog(this,e.getMessage());
}
【问题讨论】:
-
有人能帮忙解决一下上面的问题吗
-
嗨@janes,这个链接可能会帮助你“stackoverflow.com/questions/32755997/…”。看起来意图相同。
-
@Pearl 我试过了,但还是没有全部保存
-
能否提供源文件。所以,我可以在本地试试
-
您的表当前包含多少行?