@@ -38,7 +38,6 @@ public class ResultSetImpl implements ResultSet, JdbcV2Wrapper {
3838 private boolean closed ;
3939 private final StatementImpl parentStatement ;
4040 private boolean wasNull ;
41- private final Calendar defaultCalendar ;
4241
4342 public ResultSetImpl (StatementImpl parentStatement , QueryResponse response , ClickHouseBinaryFormatReader reader ) {
4443 this .parentStatement = parentStatement ;
@@ -47,7 +46,6 @@ public ResultSetImpl(StatementImpl parentStatement, QueryResponse response, Clic
4746 this .metaData = new com .clickhouse .jdbc .metadata .ResultSetMetaData (this );
4847 this .closed = false ;
4948 this .wasNull = false ;
50- this .defaultCalendar = new GregorianCalendar (TimeZone .getTimeZone ("UTC" ));
5149 }
5250
5351 protected ResultSetImpl (ResultSetImpl resultSet ) {
@@ -57,7 +55,6 @@ protected ResultSetImpl(ResultSetImpl resultSet) {
5755 this .metaData = resultSet .metaData ;
5856 this .closed = false ;
5957 this .wasNull = false ;
60- this .defaultCalendar = new GregorianCalendar (TimeZone .getTimeZone ("UTC" ));
6158 }
6259
6360 private void checkClosed () throws SQLException {
@@ -1048,17 +1045,18 @@ public Date getDate(int columnIndex, Calendar cal) throws SQLException {
10481045 public Date getDate (String columnLabel , Calendar cal ) throws SQLException {
10491046 checkClosed ();
10501047 try {
1051- LocalDate d = reader .getLocalDate (columnLabel );
1052- if (d == null ) {
1048+ ZonedDateTime zdt = reader .getZonedDateTime (columnLabel );
1049+ if (zdt == null ) {
10531050 wasNull = true ;
10541051 return null ;
10551052 }
10561053 wasNull = false ;
10571054
1058- Calendar c = (Calendar ) (cal != null ? cal : defaultCalendar ).clone ();
1059- c .clear ();
1060- c .set (d .getYear (), d .getMonthValue () - 1 , d .getDayOfMonth (), 0 , 0 , 0 );
1061- return new Date (c .getTimeInMillis ());
1055+ if (cal == null ) {
1056+ cal = new GregorianCalendar (TimeZone .getTimeZone ("UTC" ));
1057+ }
1058+
1059+ return new Date (zdt .withZoneSameLocal (cal .getTimeZone ().toZoneId ()).toInstant ().toEpochMilli ());//This assumes the response is in cal.getTimeZone()
10621060 } catch (Exception e ) {
10631061 throw ExceptionUtils .toSqlState (String .format ("Method: getDate(\" %s\" ) encountered an exception." , columnLabel ), String .format ("SQL: [%s]" , parentStatement .getLastSql ()), e );
10641062 }
@@ -1080,10 +1078,11 @@ public Time getTime(String columnLabel, Calendar cal) throws SQLException {
10801078 }
10811079 wasNull = false ;
10821080
1083- Calendar c = (Calendar )( cal != null ? cal : defaultCalendar ).clone ();
1084- c .clear ();
1085- c .set (1970 , Calendar .JANUARY , 1 , zdt .getHour (), zdt .getMinute (), zdt .getSecond ());
1086- return new Time (c .getTimeInMillis ());
1081+ if (cal == null ) {
1082+ cal = new GregorianCalendar (TimeZone .getTimeZone ("UTC" ));
1083+ }
1084+
1085+ return new Time (zdt .withZoneSameLocal (cal .getTimeZone ().toZoneId ()).toInstant ().toEpochMilli ());//This assumes the response is in cal.getTimeZone()
10871086 } catch (Exception e ) {
10881087 throw ExceptionUtils .toSqlState (String .format ("Method: getTime(\" %s\" ) encountered an exception." , columnLabel ), String .format ("SQL: [%s]" , parentStatement .getLastSql ()), e );
10891088 }
@@ -1098,23 +1097,23 @@ public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException
10981097 public Timestamp getTimestamp (String columnLabel , Calendar cal ) throws SQLException {
10991098 checkClosed ();
11001099 try {
1101- LocalDateTime localDateTime = reader .getLocalDateTime (columnLabel );
1102- if (localDateTime == null ) {
1100+ ZonedDateTime zdt = reader .getZonedDateTime (columnLabel );
1101+ if (zdt == null ) {
11031102 wasNull = true ;
11041103 return null ;
11051104 }
11061105 wasNull = false ;
1107-
1108- Calendar c = (Calendar ) (cal != null ? cal : defaultCalendar ).clone ();
1109- c .set (localDateTime .getYear (), localDateTime .getMonthValue () - 1 , localDateTime .getDayOfMonth (), localDateTime .getHour (), localDateTime .getMinute (),
1110- localDateTime .getSecond ());
1111- Timestamp timestamp = new Timestamp (c .getTimeInMillis ());
1112- timestamp .setNanos (localDateTime .getNano ());
1113- return timestamp ;
1106+
1107+ if (cal == null ) {
1108+ cal = new GregorianCalendar (TimeZone .getTimeZone ("UTC" ));
1109+ }
1110+
1111+ Timestamp ts = new Timestamp (zdt .withZoneSameLocal (cal .getTimeZone ().toZoneId ()).toInstant ().toEpochMilli ());
1112+ ts .setNanos (zdt .getNano ());
1113+ return ts ;//This assumes the response is in cal.getTimeZone()
11141114 } catch (Exception e ) {
11151115 throw ExceptionUtils .toSqlState (String .format ("Method: getTimestamp(\" %s\" ) encountered an exception." , columnLabel ), String .format ("SQL: [%s]" , parentStatement .getLastSql ()), e );
11161116 }
1117-
11181117 }
11191118
11201119 @ Override
0 commit comments