Details
-
Bug
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Fixed
-
2.6.1
-
None
Description
The getDate() method of the ResultSet returns java.sql.Date however the underlying GregorianDate has the time component. This results in failure of date comparison if assumed that the date always has time set as 00 hours.
A simple test between MySQL and MariaDB yields different results
/** Code Example **/
Properties credentials = new Properties();
credentials.setProperty("user", "abs");
credentials.setProperty("password", "xxxxxxx");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss");
//MySQL Driver
{
try(Connection con = new com.mysql.jdbc.Driver().connect("jdbc:mysql://localhost:3310/safenet?useUnicode=true&characterEncoding=UTF-8&jdbcCompliantTruncation=false&zeroDateTimeBehavior=convertToNull", credentials))
{
try(Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("select now()"))
{
if (rs.next())
}
}
catch (SQLException e)
}
//MariaDB Driver
{
try(Connection con = new org.mariadb.jdbc.Driver().connect("jdbc:mariadb://localhost:3308/safenet?useUnicode=true&characterEncoding=UTF-8&jdbcCompliantTruncation=false&zeroDateTimeBehavior=convertToNull", credentials))
{
try(Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("select now()"))
{
if (rs.next())
{ System.out.printf("MariaDB Date Returned: %s\n", sdf.format(rs.getDate(1))); }
}
}
catch (SQLException e)
{ e.printStackTrace(); }
}
/** OUTPUT **/
MySQL Date Returned: 2020-Jul-22 00:00:00
MariaDB Date Returned: 2020-Jul-22 16:42:32
===================================================
Drivers Used
===================================================
<!-- https://mvnrepository.com/artifact/org.mariadb.jdbc/mariadb-java-client -->
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>2.6.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.49</version>
</dependency>