Uploaded image for project: 'MariaDB Connector/J'
  1. MariaDB Connector/J
  2. CONJ-810

ResultSet.getDate() return value inconsistent between MySQL and MariaDB connectors

    XMLWordPrintable

    Details

      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())

      { System.out.printf("MySQL Date Returned: %s\n", sdf.format(rs.getDate(1))); }

      }
      }
      catch (SQLException e)

      { e.printStackTrace(); }
      }

      //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>

        Attachments

          Activity

            People

            Assignee:
            diego dupin Diego Dupin
            Reporter:
            bibhas@gmail.com Bibhas Sarkar
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: