|
From: Estes, J. D - S. L. M. <jam...@us...> - 2004-08-06 14:23:30
|
I'm constantly converting from util.Date to sql.Date in my Dao when I'm
passing my params to the MappingSqlQuery's execute method...not a huge
deal, its just annoying when I forget and then see it pop up at runtime.
I was wondering if spring could step in and do the conversion for me. I
believe this should really be a feature of the DB Driver, but at least
for Oracle, it complains when I try to bind a util date to a parameter
declared as a Types.DATE (stack trace snippet below). I realize that
with a sql date the time information should/will be truncated, but I
think that is the expected behavior anyway since I'm saying the type is
a Types.DATE. =20
I did some digging and found where it would be nice to have the
conversion done for me:
StatementCreatorUtils, line 106...something like
else if (sqlType =3D=3D Types.DATE && (inValue instanceof =
java.util.Date)) {
ps.setObject(paramIndex,=20
new java.sql.Date(((java.util.Date)inValue).getTime()));
}
...could be inserted.
Would this be possible? Or are there some deeper issues I'm not
thinking about. I'm pretty sure this would work well for Oracle, but
not sure about other DBs.
Thanks,
James
java.sql.SQLException: Invalid conversion requested
at
oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at
oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at
oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:269)
at
oracle.jdbc.driver.OraclePreparedStatement.setObject(OraclePreparedState
ment.java:3017)
at
oracle.jdbc.driver.OraclePreparedStatement.setObject(OraclePreparedState
ment.java:3107)
at
com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement.setObject(WSJdbcPrepar
edStatement.java:1088)
at
org.springframework.jdbc.core.StatementCreatorUtils.setParameterValue(St
atementCreatorUtils.java:107)
|