我想使用for循环更新derby db中的多个行。但是,当我尝试使用以下代码时,只有最后指定的项目已更新。
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
try {
String c = "update myschema.tblsample SET date=?, particulars=?,amount=? where blndrcr =?and index =?";
PreparedStatement st = conn.prepareStatement(c);
for (int j = 0; j < i - 1; j++) {
st.setString(1, td.getText());
st.setString(2, v1[j]);
st.setInt(3, v2[j]);
st.setBoolean(4, dr[i]);
st.setInt(5, Integer.parseInt(tnoe.getText()));
int kk = st.executeUpdate();
if (kk > 0) {
System.out.println("Addedd successfully !");
}
}
} catch (SQLException ex) {
Logger.getLogger(sample.class.getName()).log(Level.SEVERE, null, ex);
}
}
任何人请帮助我