【发布时间】:2014-08-11 16:13:09
【问题描述】:
我正在尝试从我的数据库中检索 Timestamp,我需要将其转换为 java.util.Date
我一直在关注我在 stackoverflow 中找到的几个示例,但我不断收到以下异常:
java.lang.IllegalArgumentException: Timestamp format must be yyyy-mm-dd hh:mm:ss[.fffffffff]
我不知道为什么,我已经尝试了几种方法,你能帮帮我吗?
这是我的代码:
//select all partitions from table "LDRS"
stmtSelect = connection.prepareCall("Select HIGH_VALUE from user_tab_partitions where table_name = 'LDRS'");
ResultSet rs = stmtSelect.executeQuery();
SimpleDateFormat myFormat = new SimpleDateFormat("dd.MM.yyyy");
while (rs.next()) {
try {
Timestamp ts = rs.getTimestamp("HIGH_VALUE");
Date date1 = myFormat.parse(ts.toString());
Date date2 = myFormat.parse(""+new Date());
// compares the current date with the partition date, if the difference between them is more than 30 days
// drops the partition
long diff = date2.getTime() - date1.getTime();
...
}
【问题讨论】: