I have a table in PostgreSQL (9.3) with a daterange field type .
I can select this field as String with JDBC, but I cannot insert it into the table.
What I tried:
PreparedStatement stm = conn.prepareStatement("insert into mytable (my_daterange_field) values (?)"); stm.setString(1, "[2014-01-02,2014-01-04]"); int i = stm.executeUpdate();
and I got:
Exception in thread "main" org.postgresql.util.PSQLException: ERROR: column "my_daterange_field" is of type daterange but expression is of type character varying Hint: You will need to rewrite or cast the expression. Position: 168
Does anyone have a solution to insert daterange? Which stm.setXXX should be used? Or maybe I can't do this because the JDBC driver does not support daterange ... Maybe there is a third solution?
Thanks.
PS
My PostgreSQL JDBC driver:
<dependency> <groupId>postgresql</groupId> <artifactId>postgresql</artifactId> <version>8.4-701.jdbc4</version> </dependency>
source share