【发布时间】:2015-03-05 04:59:42
【问题描述】:
在 MY_TABLE 中,当 ORD_AMT 字段更新时,LST_UPDT_TS 也会用 current_timestamp 更新。由以下查询提出:
UPDATE MY_TABLE
SET ORD_AMT = 50, LST_UPDT_TS = CURRENT_TIMESTAMP
WHERE ORD_ID = 'ORD_123'
我需要通过 JDBC 代码来实现这个业务,而且我的 Web 服务器和 DB 服务器是不同的时区。如果我将 Date().getTime() 传递给 JDBC,它是 Web 服务器的当前时间,但我需要 DB 服务器的当前时间。
有没有办法像这样传递 CURRENT_TIMESTAMP:
preparedStatement = dbConnection.prepareStatement(updateOrderSql);
preparedStatement.setFloat(1, 50);
preparedStatement.setTimestamp(2, Timestamp.CURRENT_TIMESTAMP);
preparedStatement.setString(3, 'ORD_123');
preparedStatement.executeUpdate();
感谢您的帮助。
【问题讨论】:
-
您不能将
CURRENT_TIMESTAMP作为参数传递。只需将关键字保留在您的 SQL 中,不要将其替换为?