package cz.michal.database.test; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.time.OffsetDateTime; /** * Incomplete demonstration that cannot be run - see {@link MySQLOffsetDateTimeTest} * for full example. */ @SuppressWarnings( "unused" ) public class MySQLOffsetDateTimeTestShort { private Connection connection; /** * Test. */ private void run() throws SQLException { // Load the first column of the TEST table. Statement statement = connection.createStatement(); ResultSet row = statement.executeQuery( "SELECT * FROM test" ); row.next(); // Attempt to parse the columns as OffsetDateTime. // "dt" is a DATETIME or "TIMESTAMP" column. // Always throws an exception: /* java.sql.SQLException: Conversion not supported for type java.time.OffsetDateTime at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63) at com.mysql.cj.jdbc.result.ResultSetImpl.getObject(ResultSetImpl.java:1476) at com.mysql.cj.jdbc.result.ResultSetImpl.getObject(ResultSetImpl.java:1483) */ OffsetDateTime date = row.getObject( "dt", OffsetDateTime.class ); } }