Java date & time datatypes are as everybody knows, there’s no need to focus on that.
However, when I’m using JDBC or Spring-based extensions, such as SimpleJdbcTemplate to retrieve and store interval values, what Java type should I use, if I don’t want to use org.postgresql.util.PGInterval class?
This class is internal of PostgreSQL driver so using it would make the code DB-specific. I think it should be possible to operate on intervals in DB-agnostic way, because it is one of standard SQL types.
An interval isn’t one of the standard JDBC Types, as listed in the
java.sql.Typesclass. I know that if you callresultSet.getObject("interval_column"), it is aPGIntervalwhen casted, so it looks like the PG JDBC driver might be forcing your hand to deal with it as such, unless you do what Glenn says and convert it to a string, or maybe a number, in your SQL.In our application, we use JodaTime for all of our date management, and we have a Hibernate Type written that converts our bean property to and from a
PGInterval, and usegetObjectandsetObjectto communicate with JDBC. I doubt that code would help you deal with what you are looking for here, but I can share it with you if you are interested.UPDATED: Here is the Hibernate Type class that converts between Joda Time and PGInterval. I know this doesn’t answer the question, but the original poster asked for the sample code.