Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8186415

java.sql.Time does not have sufficient precision for new MySQL Time columns

    Details

    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      FULL PRODUCT VERSION :
      java version "1.8.0_131"
      Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
      Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux 3.10.0-514.16.1.el7.x86_64 on AWS, but this is surely not important

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      MySQL 5.7.18-14 with tokudb

      A DESCRIPTION OF THE PROBLEM :
      MySQL 5.7 has added support for fractional second precision in time-fields. https://dev.mysql.com/doc/refman/5.7/en/fractional-seconds.html

      java.sql.Time truncates to second.

      You can no longer use java.sql.Time to set a time column accurately.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Use the milliseconds constructor on java.sql.Time to create a Time object with a milliseconds component. Use Time.getTime() to see the milliseconds are set. Store to a MySQL table with Time(3) column. Inspect the DB column to see if the milliseconds have been stored.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      That the millseconds of the time are stored in the DB column.
      ACTUAL -
      The DB column times have 0 milliseconds.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      CUSTOMER SUBMITTED WORKAROUND :
      It seems you can set a time column with a java.sql.Timestamp and MySQL will ignore the date component but set the time component with milliseconds. Presumably this is a bit more overhead on the wire?

        Attachments

          Activity

            People

            • Assignee:
              lancea Lance Andersen
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: