@@ -1630,11 +1630,12 @@ public static Timestamp toTimestamp(String s, ResultSet resultSet)
1630
1630
1631
1631
// Copy s into sbuf for parsing.
1632
1632
resultSet .sbuf .append (s );
1633
+ int slen = s .length ();
1633
1634
1634
- if (s . length () > 19 )
1635
+ if (slen > 19 )
1635
1636
{
1636
1637
// The len of the ISO string to the second value is 19 chars. If
1637
- // greater then 19, there should be tz info and perhaps fractional
1638
+ // greater then 19, there may be tz info and perhaps fractional
1638
1639
// second info which we need to change to java to read it.
1639
1640
1640
1641
// cut the copy to second value "2001-12-07 16:29:22"
@@ -1651,7 +1652,7 @@ public static Timestamp toTimestamp(String s, ResultSet resultSet)
1651
1652
if (i < 24 )
1652
1653
resultSet .sbuf .append (c );
1653
1654
c = s .charAt (i ++);
1654
- } while (Character .isDigit (c ));
1655
+ } while (i < slen && Character .isDigit (c ));
1655
1656
1656
1657
// If there wasn't at least 3 digits we should add some zeros
1657
1658
// to make up the 3 digits we tell java to expect.
@@ -1664,21 +1665,29 @@ public static Timestamp toTimestamp(String s, ResultSet resultSet)
1664
1665
resultSet .sbuf .append (".000" );
1665
1666
}
1666
1667
1667
- // prepend the GMT part and then add the remaining bit of
1668
- // the string.
1669
- resultSet .sbuf .append (" GMT" );
1670
- resultSet .sbuf .append (c );
1671
- resultSet .sbuf .append (s .substring (i , s .length ()));
1672
-
1673
- // Lastly, if the tz part doesn't specify the :MM part then
1674
- // we add ":00" for java.
1675
- if (s .length () - i < 5 )
1676
- resultSet .sbuf .append (":00" );
1677
-
1678
- // we'll use this dateformat string to parse the result.
1679
- df = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss.SSS z" );
1668
+ if (i < slen )
1669
+ {
1670
+ // prepend the GMT part and then add the remaining bit of
1671
+ // the string.
1672
+ resultSet .sbuf .append (" GMT" );
1673
+ resultSet .sbuf .append (c );
1674
+ resultSet .sbuf .append (s .substring (i , slen ));
1675
+
1676
+ // Lastly, if the tz part doesn't specify the :MM part then
1677
+ // we add ":00" for java.
1678
+ if (slen - i < 5 )
1679
+ resultSet .sbuf .append (":00" );
1680
+
1681
+ // we'll use this dateformat string to parse the result.
1682
+ df = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss.SSS z" );
1683
+ }
1684
+ else
1685
+ {
1686
+ // Just found fractional seconds but no timezone.
1687
+ df = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss.SSS" );
1688
+ }
1680
1689
}
1681
- else if (s . length () == 19 )
1690
+ else if (slen == 19 )
1682
1691
{
1683
1692
// No tz or fractional second info.
1684
1693
// I'm not sure if it is
0 commit comments