Java 如何在数据库中编辑/更新jtable单元格值

Java 如何在数据库中编辑/更新jtable单元格值,java,Java,我正在尝试编辑和更新jtable单元格,如下代码所示。我的问题是,当更新一行时,所有其他行都会得到相同的值。我的意思是只有一行被更新,而所有其他行都被复制。任何人都可以用一个好的方法来帮助我们。谢谢 int count = Table_purchase.getRowCount(); int col = Table_purchase.getColumnCount(); String pod_id[] = new String[count]; String po_id

我正在尝试编辑和更新jtable单元格,如下代码所示。我的问题是,当更新一行时,所有其他行都会得到相同的值。我的意思是只有一行被更新,而所有其他行都被复制。任何人都可以用一个好的方法来帮助我们。谢谢

    int count = Table_purchase.getRowCount();
    int col = Table_purchase.getColumnCount();
    String pod_id[] = new String[count];
    String po_id[] = new String[count];
    String order_qty[] = new String[count];
    String item_id[] = new String[count];
    String unit_price[] = new String[count];
    String recived_qty[] = new String[count];
    String rejected_qty[] = new String[count];

    for (int i = 0; i < count; i++) {
        po_id[i] = Table_purchase.getValueAt(i,0).toString();
        pod_id[i] = Table_purchase.getValueAt(i,1).toString();
        order_qty[i] = Table_purchase.getValueAt(i,2).toString();
        item_id[i] = Table_purchase.getValueAt(i,3).toString();
        unit_price[i] = Table_purchase.getValueAt(i,4).toString();
        recived_qty[i] = Table_purchase.getValueAt(i, 5).toString();
        rejected_qty[i] = Table_purchase.getValueAt(i,6).toString();

        try {
            String sql = "update purchase.purchase_detail set pod_id='" + pod_id[i] + "',order_qty='" + order_qty[i] + "',item_id='" + item_id[i] + "', unit_price='" + unit_price[i] + "', recived_qty='" + recived_qty[i] + "',rejected_qty='" + rejected_qty[i] + "'where  po_id= '" +  po_id[i] + "'";
            pst = conn.prepareStatement(sql);
            pst.execute();
            JOptionPane.showMessageDialog(null, "updated");
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e);
        }  

    }
int count=Table_purchase.getRowCount();
int col=Table_purchase.getColumnCount();
字符串pod_id[]=新字符串[计数];
字符串po_id[]=新字符串[计数];
字符串订单数量[]=新字符串[计数];
字符串项_id[]=新字符串[计数];
字符串单价[]=新字符串[计数];
字符串接收数量[]=新字符串[计数];
字符串被拒绝\u数量[]=新字符串[计数];
for(int i=0;i
您的sql语句不包含where子句,因此对于swing表行的每次迭代,都会更新数据库表中的所有行,最后,所有数据库行都将具有来自上一个swing表行的值

(并且,请使用pst.setParameter(),不要将sql混合到gui代码中。)