2121import java .net .URL ;
2222import java .nio .file .Path ;
2323import java .sql .*;
24+ import java .text .DateFormat ;
25+ import java .text .ParseException ;
2426import java .util .Calendar ;
2527import java .util .HashMap ;
2628import java .util .Map ;
@@ -236,9 +238,15 @@ public Date getDate(int columnIndex) throws SQLException {
236238 return null ;
237239 if (val instanceof Date )
238240 return (Date ) val ;
241+ if (val instanceof Timestamp )
242+ return new Date (((Timestamp ) val ).getTime ());
239243 if (val instanceof Number )
240244 return new Date (((Number ) val ).longValue ());
241- return new Date (Long .parseLong (val .toString ()));
245+ try {
246+ return new Date (DateFormat .getDateInstance ().parse (val .toString ()).getTime ());
247+ } catch (ParseException e ) {
248+ throw new SQLException ("Unexpected Date type (" + val .getClass () + ") on column " + columnIndex , e );
249+ }
242250 }
243251
244252 @ Override
@@ -250,7 +258,11 @@ public Time getTime(int columnIndex) throws SQLException {
250258 return (Time ) val ;
251259 if (val instanceof Number )
252260 return new Time (((Number ) val ).longValue ());
253- return new Time (Long .parseLong (val .toString ()));
261+ try {
262+ return new Time (DateFormat .getTimeInstance ().parse (val .toString ()).getTime ());
263+ } catch (ParseException e ) {
264+ throw new SQLException ("Unexpected Time type (" + val .getClass () + ") on column " + columnIndex , e );
265+ }
254266 }
255267
256268 @ Override
@@ -262,7 +274,11 @@ public Timestamp getTimestamp(int columnIndex) throws SQLException {
262274 return (Timestamp ) val ;
263275 if (val instanceof Number )
264276 return new Timestamp (((Number ) val ).longValue ());
265- return new Timestamp (Long .parseLong (val .toString ()));
277+ try {
278+ return new Timestamp (DateFormat .getDateTimeInstance ().parse (val .toString ()).getTime ());
279+ } catch (ParseException e ) {
280+ throw new SQLException ("Unexpected Timestamp type (" + val .getClass () + ") on column " + columnIndex , e );
281+ }
266282 }
267283
268284 @ Override
0 commit comments