From bf6799b0ce709bb15725294116baa824705f1169 Mon Sep 17 00:00:00 2001 From: bernd Date: Wed, 14 Nov 2012 21:24:31 +0100 Subject: [PATCH 11/25] DateMapper now calls ResultSet.getTimeStamp() and then ResultSet.getObject() and if that fails ResultSet.getDate() (rather than relying on ResultSet.getObject() returning a java.util.Date) as not all database drivers return the same type when calling getObject() (issue found with SQLite JDBC driver) --- .../src/net/lemnik/eodsql/impl/DefaultTypeMappers.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/eodsql/src/net/lemnik/eodsql/impl/DefaultTypeMappers.java b/eodsql/src/net/lemnik/eodsql/impl/DefaultTypeMappers.java index 74260ad..e8c21a3 100644 --- a/eodsql/src/net/lemnik/eodsql/impl/DefaultTypeMappers.java +++ b/eodsql/src/net/lemnik/eodsql/impl/DefaultTypeMappers.java @@ -458,7 +458,23 @@ class DefaultTypeMappers { final int column) throws SQLException { - return (Date)results.getObject(column); + try { + return results.getTimestamp(column); + } catch (SQLException sqle) { + try { + final Object obj = results.getObject(column); + if (obj instanceof Long) { + return new Date((Long) obj); + } else { + return (Date) obj; + } + } catch (SQLException ex) + { + return results.getDate(column); + } catch (ClassCastException ex) { + return results.getDate(column); + } + } } public void set( -- 1.8.0