Uploaded image for project: 'Derby'
  1. Derby
  2. DERBY-4621

Invalid conversion from Timestamp to String when calling setTimestamp() with Calendar

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 10.5.3.0
    • 10.5.3.1, 10.6.1.0
    • SQL
    • None
    • Repro attached
    • Wrong query result

    Description

      If you set a VARCHAR parameter with setTimestamp(), the string will be formatted differently depending on whether a Calendar is specified or not, even if the default calendar is used.

      Take for example this statement:

      VALUES CAST(? AS VARCHAR(30))

      I executed this statement twice with the same Timestamp instance. First like this:

      ps.setTimestamp(1, ts);

      and then like this

      ps.setTimestamp(1, ts, Calendar.getInstance());

      In this example, both of the methods should use the default Calendar to convert the timestamp to a string. However, I see that they generate different strings:

      2010-04-20 15:17:36.0 vs 2010-04-20 03:17:36

      Note there are two differences:

      1) The method that takes a Calendar object does not show the fraction part (.0)

      2) The method that takes a Calendar object is 12 hours off (03 instead of 15)

      Attachments

        1. TimestampToVarchar.java
          0.8 kB
          Knut Anders Hatlen
        2. derby-4621.diff
          4 kB
          Knut Anders Hatlen

        Issue Links

          Activity

            People

              knutanders Knut Anders Hatlen
              knutanders Knut Anders Hatlen
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: