【发布时间】:2017-08-10 06:08:39
【问题描述】:
此查询在开始时有效,但当我一次又一次地更新它时它停止工作。我正在使用 netbeans 并使用 xampp 服务器。
还有一件奇怪的事情,现在当值更新时,最后两行和最后一列保持不变。
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
String val = txt_val.getText();
String col = txt_col.getText();
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost/net", "root", "");
pstmt = conn.prepareStatement(
"update userdetail set
name = ?
, username = ? where name = ? AND username = ? ")
pstmt.setString(1, val);
pstmt.setString(2, val);
pstmt.setString(3, col);
pstmt.setString(4, col);
int i = pstmt.executeUpdate();
if (i > 0) {
JOptionPane.showMessageDialog(null, "done");
} else {
JOptionPane.showMessageDialog(null, "query failed");
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
}
【问题讨论】:
标签: java mysql jdbc xampp netbeans-8