|
From: Estes, J. D - S. L. M. <jam...@us...> - 2004-08-09 13:17:31
|
I believe it would be appropriate. Version with those checks included =
(slightly modified for performance when type is not time related):
else if (sqlType =3D=3D Types.DATE){
if((inValue instanceof java.util.Date) &&
!(inValue instanceof java.sql.Date)) {
inValue =3D=20
new java.sql.Date(((java.util.Date)inValue).getTime());
}
ps.setObject(paramIndex, inValue, Types.DATE);
}
else if(sqlType =3D=3D Types.TIMESTAMP){
if((inValue instanceof java.util.Date) &&
!(inValue instanceof java.sql.Timestamp)) {
inValue =3D=20
new java.sql.Timestamp(((java.util.Date)inValue).getTime());
}
ps.setObject(paramIndex, inValue, Types.TIMESTAMP);
}
else if(sqlType =3D=3D Types.TIME){
if((inValue instanceof java.util.Date) &&
!(inValue instanceof java.sql.Time)) {
inValue =3D=20
new java.sql.Time (((java.util.Date)inValue).getTime());
}
ps.setObject(paramIndex, inValue, Types.TIME);
}
James
-----Original Message-----
From: spr...@li... =
[mailto:spr...@li...] On Behalf =
Of j=FCrgen h=F6ller [werk3AT]
Sent: Monday, August 09, 2004 7:48 AM
To: spr...@li...
Subject: Re: [Springframework-developer] java.util.Date to java.sql.Date
Sounds plausible! I'm inclined to add this extra check.
Would it be appropriate to add similar checks for java.sql.Time and =
java.sql.Timestamp too?
Thomas, Rod, others - any thoughts on this?
Juergen
-----Original Message-----
From: spr...@li...
[mailto:spr...@li...]On Behalf
Of Estes, James D - St. Louis, MO
Sent: Monday, August 09, 2004 12:43 PM
To: spr...@li...
Subject: RE: [Springframework-developer] java.util.Date to java.sql.Date
...forgot to see if it is already a sql date:
else if (sqlType =3D=3D Types.DATE && (inValue instanceof =
java.util.Date) &&
!(inValue instanceof java.sql.Date)) {
ps.setObject(paramIndex,=20
new java.sql.Date(((java.util.Date)inValue).getTime()));
}
-----Original Message-----
From: spr...@li...
[mailto:spr...@li...] On Behalf
Of Estes, James D - St. Louis, MO
Sent: Friday, August 06, 2004 9:23 AM
To: spr...@li...
Subject: [Springframework-developer] java.util.Date to java.sql.Date
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)
-------------------------------------------------------
This SF.Net email is sponsored by OSTG. Have you noticed the changes on
Linux.com, ITManagersJournal and NewsForge in the past few weeks? Now,
one more big change to announce. We are now OSTG- Open Source Technology
Group. Come see the changes on the new OSTG site. www.ostg.com
_______________________________________________
Springframework-developer mailing list
Spr...@li...
https://lists.sourceforge.net/lists/listinfo/springframework-developer
-------------------------------------------------------
This SF.Net email is sponsored by OSTG. Have you noticed the changes on
Linux.com, ITManagersJournal and NewsForge in the past few weeks? Now,
one more big change to announce. We are now OSTG- Open Source Technology
Group. Come see the changes on the new OSTG site. www.ostg.com
_______________________________________________
Springframework-developer mailing list
Spr...@li...
https://lists.sourceforge.net/lists/listinfo/springframework-developer
-------------------------------------------------------
This SF.Net email is sponsored by OSTG. Have you noticed the changes on
Linux.com, ITManagersJournal and NewsForge in the past few weeks? Now,
one more big change to announce. We are now OSTG- Open Source Technology
Group. Come see the changes on the new OSTG site. www.ostg.com
_______________________________________________
Springframework-developer mailing list
Spr...@li...
https://lists.sourceforge.net/lists/listinfo/springframework-developer
|