nurkiewicz / spring-data-jdbc-repository

Spring Data JDBC generic DAO implementation
275 stars 151 forks source link

PostgreSQL problems with Date and Timestamp types #24

Open MarkHamby opened 9 years ago

MarkHamby commented 9 years ago

Using PostgreSQL and Java 7, the createPreparedStatement in createWithAutoGeneratedKey sould not handle java.sql.Date and java.sql.Timestamp parameters correctly. Not a JDBC Repository issue directly; apparently, PostgreSQL's PreparedStatement setObject(i,v) does not determine the type. I had to add the following code.

if (queryParams[i] instanceof java.sql.Date) {
    ps.setObject(i + 1, queryParams[i], java.sql.Types.DATE );                      
}
else if (queryParams[i] instanceof java.sql.Timestamp) {
    ps.setObject(i + 1, queryParams[i], java.sql.Types.TIMESTAMP );                     
}
else {
    ps.setObject(i + 1, queryParams[i]);
}

I thought I'd let you know. I love this package.

Mark