我无法通过编辑/更改单元格值并单击更新按钮来更新数据库中的数据,但他无法更改我更改为单元格的数据库.它仍然与最后一个值相同.
这是我的代码:
public void directlyup() {
int col=tablesample.getSelectedColumn();
int row=tablesample.getSelectedRow();
int index;
index = Integer.parseInt(tablesample.getModel().getValueAt(row, 0).toString());
try {
String sql ="UPDATE invoice SET description = ?,qty = ?,unitprice = ?"
+ ",total = ? WHERE id ="+row;
pst = conn.prepareStatement(sql);
pst.setString(1, (String) tablesample.getValueAt(row, 1));
pst.setString(2, (String) tablesample.getValueAt(row, 2));
pst.setString(3, (String) tablesample.getValueAt(row, 3));
pst.setString(4, (String) tablesample.getValueAt(row, 4));
pst.execute();
JOptionPane.showMessageDialog(null, "Successfully Updated");
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
}
Run Code Online (Sandbox Code Playgroud)