@@ -47,10 +47,13 @@ public class QueryServiceResultSet implements ResultSet {
47
47
private final AtomicBoolean closed = new AtomicBoolean ();
48
48
private final AtomicBoolean wasNull = new AtomicBoolean ();
49
49
protected ResultSetMetaData resultSetMetaData ;
50
- //private SimpleDateFormat dateFormatterWithTime = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
50
+
51
51
//To fix the Invalid Date format issue
52
- private SimpleDateFormat dateFormatterWithTime = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss.SSS Z" );
53
- private SimpleDateFormat dateFormatter = new SimpleDateFormat ("yyyy-MM-dd" );
52
+ private final String dateSimple = "yyyy-MM-dd" ;
53
+ private final String dateISOStandard = "yyyy-MM-dd'T'HH:mm:ss" ;
54
+ private final String dateWithSeconds = "yyyy-MM-dd HH:mm:ss" ;
55
+ private final String dateWithMsTz = "yyyy-MM-dd HH:mm:ss.SSS Z" ;
56
+
54
57
protected QueryServiceAbstractStatement statement ;
55
58
private int currentPageNum = 1 ;
56
59
@@ -811,6 +814,7 @@ public Date getDate(int columnIndex, Calendar cal) throws SQLException {
811
814
return getDate (columnNameByIndex , cal );
812
815
}
813
816
817
+ //Handle multiple date formats one by one
814
818
@ Override
815
819
public Date getDate (String columnLabel , Calendar cal ) throws SQLException {
816
820
errorOutIfClosed ();
@@ -819,20 +823,25 @@ public Date getDate(String columnLabel, Calendar cal) throws SQLException {
819
823
wasNull .set (true );
820
824
return null ;
821
825
}
822
- dateFormatter .setTimeZone (cal .getTimeZone ());
823
- dateFormatterWithTime .setTimeZone (cal .getTimeZone ());
826
+ String [] formats = new String [] {dateWithMsTz , dateISOStandard , dateWithSeconds , dateSimple };
824
827
try {
825
828
String valueString = value .toString ();
826
- if (valueString .length () == 10 ) {
827
- cal .setTime (dateFormatter .parse (value .toString ()));
828
- } else {
829
- cal .setTime (dateFormatterWithTime .parse (value .toString ()));
829
+ for (String format : formats ) {
830
+ SimpleDateFormat sdFormat = new SimpleDateFormat (format );
831
+ sdFormat .setTimeZone (cal .getTimeZone ());
832
+ try {
833
+ cal .setTime (sdFormat .parse (valueString ));
834
+ return new Date (cal .getTimeInMillis ());
835
+ } catch (ParseException e ) {
836
+ log .info ("QSRS: caught exp {}" , e .getMessage ());
837
+ log .warn ("QSRS: Date format does not match the formatter, trying another format" , e );
838
+ }
830
839
}
831
- return new Date (cal .getTimeInMillis ());
832
840
}
833
- catch (IllegalArgumentException | ParseException e ) {
841
+ catch (IllegalArgumentException e ) {
834
842
throw new SQLException ("Invalid date from server: " + value , e );
835
843
}
844
+ return null ;
836
845
}
837
846
838
847
@ Override
0 commit comments