package de.bjrke.mysqlbug; import com.mysql.cj.jdbc.util.BaseBugReport; import java.sql.SQLException; import java.sql.Time; import java.util.TimeZone; import java.util.concurrent.TimeUnit; public class TimeBug extends BaseBugReport { @Override public void setUp() throws SQLException { TimeZone.setDefault(TimeZone.getTimeZone("UTC")); try (final var con = getConnection()) { try (final var stm = con.prepareStatement("CREATE TABLE IF NOT EXISTS timebug (time TIME PRIMARY KEY NOT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci")) { stm.execute(); } try (final var stm = con.prepareStatement("REPLACE INTO timebug (time) VALUES (?)")) { stm.setTime(1, new Time(TimeUnit.DAYS.toMillis(1) - 250)); stm.execute(); } } } @Override public void tearDown() throws SQLException { try (final var con = getConnection()) { try (final var stm = con.prepareStatement("DROP TABLE timebug")) { stm.execute(); } } } @Override public void runTest() throws SQLException { try (final var con = getConnection(); final var stm = con.prepareStatement("SELECT time FROM timebug"); final var rs = stm.executeQuery()) { while (rs.next()) { System.out.println(rs.getTime("time")); } } } public static void main(String[] args) throws Exception { new TimeBug().run(); } }