Announcement Announcement Module
Collapse
No announcement yet.
cannot automatically insert a date type? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • cannot automatically insert a date type?

    I have a bean with longs, strings and a Date field, but spring can't seem to find the sql type for a Date. I've been using java.util.Date, but I tried java.sql.Date and got the same thing.

    [2009-10-08 08:02:37,483] [SimpleJdbcInsert] [DEBUG] The following parameters are used for call <correct SQL INSERT statement> with: [org.springframework.jdbc.core.SqlParameterValue@5f 2db0, org.springframework.jdbc.core.SqlParameterValue@b0 a3f5, org.springframework.jdbc.core.SqlParameterValue@dc 41c5, org.springframework.jdbc.core.SqlParameterValue@62 14f5, null]
    [2009-10-08 08:02:37,483] [JdbcTemplate] [DEBUG] Executing SQL update and returning generated keys
    [2009-10-08 08:02:37,483] [JdbcTemplate] [DEBUG] Executing prepared SQL statement
    [2009-10-08 08:02:37,483] [TransactionSynchronizationManager] [TRACE] Retrieved value [org.springframework.jdbc.datasource.ConnectionHold er@97d026] for key [org.springframework.jdbc.datasource.DriverManagerD ataSource@81a197] bound to thread [main]
    [2009-10-08 08:02:37,483] [SimpleJdbcInsert] [DEBUG] Using generated keys support with array of column names.
    [2009-10-08 08:02:37,483] [StatementCreatorUtils] [DEBUG] Overriding typeinfo with runtime info from SqlParameterValue: column index 1, SQL type -5, Type name null
    [2009-10-08 08:02:37,483] [StatementCreatorUtils] [TRACE] Setting SQL statement parameter value: column index 1, parameter value [21], value class [java.lang.Long], SQL type -5
    [2009-10-08 08:02:37,484] [StatementCreatorUtils] [DEBUG] Overriding typeinfo with runtime info from SqlParameterValue: column index 2, SQL type 12, Type name null
    [2009-10-08 08:02:37,484] [StatementCreatorUtils] [TRACE] Setting SQL statement parameter value: column index 2, parameter value [server hostname], value class [java.lang.String], SQL type 12
    [2009-10-08 08:02:37,484] [StatementCreatorUtils] [DEBUG] Overriding typeinfo with runtime info from SqlParameterValue: column index 3, SQL type 12, Type name null
    [2009-10-08 08:02:37,484] [StatementCreatorUtils] [TRACE] Setting SQL statement parameter value: column index 3, parameter value [localhost], value class [java.lang.String], SQL type 12
    [2009-10-08 08:02:37,485] [StatementCreatorUtils] [DEBUG] Overriding typeinfo with runtime info from SqlParameterValue: column index 4, SQL type 12, Type name null
    [2009-10-08 08:02:37,485] [StatementCreatorUtils] [TRACE] Setting SQL statement parameter value: column index 4, parameter value [oops, localdoman can't be found for some reason], value class [java.lang.String], SQL type 12
    [2009-10-08 08:02:37,485] [StatementCreatorUtils] [TRACE] Setting SQL statement parameter value: column index 5, parameter value [null], value class [null], SQL type unknown
    I got SQL type for java.util.Date to be 93 and java.sql.Date to be 91 from the static StatementCreatorUtils.javaTypeToSqlParameterType() call. The API says it will return null if no mapping is found, so I think it should work. Maybe I'm doing something wrong? (quite likely)

    This is a Postgres DB, the column is a timestamp without time zone type, and constrained to be not null, hence it blows up here.

    I would be very appreciative of any help you can give.
    Thanks.

  • #2
    I did find this link, which uses the same methods I'm using but it's not working for me?

    http://www.java2s.com/Code/Java/Spri...eterSource.htm

    Comment


    • #3
      More info:

      Got into the java.sql.Types (where the values are tied to) and got these results:

      Types.DATE=91, Types.TIME=92, Types.TIMESTAMP=93

      so spring is classifying my bean property to a java.sql.Types, but not able to handle it?

      Comment

      Working...
      X