0

我正在尝试更新我的表“总计”:

在 id = 1 的行中,我想将“days_left”的值更新为 47。

String values_to_update = "UPDATE total SET days_left = '47' where id = '1'";
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(url, "root", "Admin");
PreparedStatement ps = con.prepareStatement(values_to_update);
con.close();

为什么不更新?

4

3 回答 3

1

您需要执行准备好的语句。尝试:

ps.executeUpdate(); 
con.commit();

在关闭连接之前。

于 2012-12-02T00:21:43.937 回答
1

至少,您需要通过以下方式执行 SQL 语句:ps.executeUpdate();

于 2012-12-02T00:22:29.307 回答
1

做 ...

ps.executeUpdate()

...在关闭连接之前。看起来您也不需要准备好的声明。一份声明将适用于您的情况。

于 2012-12-02T00:23:24.750 回答