我正在使用以下语句从我的 SQL DB 中获取时间戳:
stmt.setTimestamp(i++, new java.sql.Timestamp(example.getExampleDate().getTime()))
哪个工作得很好并返回:
2013-02-22 12:27:34.0
现在碰巧我需要它更精确,像这样:
2013-02-22 12:27:34.000
所以我在文档中找到了以下方法,这显然正是我想要的:
setNanos(int n)
将此 Timestamp 对象的 nanos 字段设置为给定值。
但我需要弄清楚如何将其包含在我准备好的陈述中?
我试过例如
stmt.setTimestamp(i++, new java.sql.Timestamp(example.getExampleDate().getTime()).setNanos(3));
但除此之外返回以下错误:
The method setTimestamp(int, Timestamp) in the type PreparedStatement is not applicable for the arguments (int, void)
非常感谢你的帮助!