Timestamp data type

374 views
Skip to first unread message

Gérald

unread,
Oct 5, 2010, 11:17:00 AM10/5/10
to H2 Database
Hello,

I have a table jam_monitor with a column mon_last_access of type
timestamp. I am running a query "select * from jam_monitor where
mon_last_access between ? and ?" with a PreparedStatement. Parameters
are pushed in the statement with the type java.sql.Timestamp.

Yet I get an exception and can't make it work:
Caused by: org.h2.jdbc.JdbcSQLException: Cannot parse timestamp
constant "110", cause: "format yyyy-mm-dd"; SQL statement:
select * from jam_monitor where mon_source=? and mon_label=? and
mon_last_value between ? and ? order by mon_last_value [90011-143]
at
org.h2.message.DbException.getJdbcSQLException(DbException.java:327)
at org.h2.message.DbException.get(DbException.java:167)
at org.h2.util.DateTimeUtils.parseDateTime(DateTimeUtils.java:
257)
at
org.h2.value.ValueTimestamp.parseTimestamp(ValueTimestamp.java:81)
at org.h2.value.Value.convertTo(Value.java:758)
at org.h2.expression.Comparison.getValue(Comparison.java:228)
at
org.h2.expression.ConditionAndOr.getValue(ConditionAndOr.java:83)
at
org.h2.expression.ConditionAndOr.getValue(ConditionAndOr.java:90)
at
org.h2.expression.Expression.getBooleanValue(Expression.java:185)
at org.h2.command.dml.Select.queryFlat(Select.java:495)
at org.h2.command.dml.Select.queryWithoutCache(Select.java:
580)
at org.h2.command.dml.Query.query(Query.java:241)
at org.h2.command.CommandContainer.query(CommandContainer.java:
80)
at org.h2.command.Command.executeQuery(Command.java:132)
at
org.h2.jdbc.JdbcPreparedStatement.executeQuery(JdbcPreparedStatement.java:
96)
at org.springframework.jdbc.core.JdbcTemplate
$1.doInPreparedStatement(JdbcTemplate.java:648)
at
org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:
591)
... 8 more

I am using H2DB 1.2.134

Gérald

unread,
Oct 8, 2010, 7:52:32 AM10/8/10
to H2 Database
The problem was that I used the wrong column which was of type INTEGER
(and not TIMESTAMP). As result Integer/Timestamp comparison failed
because H2 converts the Integer into a String and then tries to parse
the String with a Timestamp format.

I regret error message wasn't clearer, I would have solved my mistake
quicker.

Gérald
Reply all
Reply to author
Forward
0 new messages