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

ResultSet of PreparedStatement return NULL When TIME column value=00:00:00

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.3.2
    • Fix Version/s: 1.3.3
    • Component/s: Other
    • Labels:
      None
    • Environment:
      OS : Windows XP 5.01. 2600 Service Pack 3
      DB : MariaDB 10.1.9
      JDBC driver : mariadb-java-client 1.3.2
      JDK : 1.8.0_66

      Description

      When TIME type column value=00:00:00, using Statement is OK and return 00:00:00.
      But using PreparedStatement is NOT OK and return NULL.

      // DDL & DML
      create table BILLING.TIME_PERIOD (
      ID int unsigned NOT NULL,
      START time NOT NULL,
      END time NOT NULL,
      PRIMARY KEY (ID)
      ) engine=InnoDB DEFAULT CHARSET=big5

      insert into time_period(id, start, end) values(1, '00:00:00', '08:00:00');

      // Test Code
      package com.cc.test

      import java.sql.Connection;
      import java.sql.DriverManager;
      import java.sql.PreparedStatement;
      import java.sql.ResultSet;
      import java.sql.Statement;

      import org.junit.After;
      import org.junit.Before;
      import org.junit.Test;

      public class MariaDbJdbcDriverTest {

      private final String URL = "jdbc:mariadb://localhost:3306/billing";
      private final String USER = "root";
      private final String PWD = "root";
      private Connection connection;

      @Before
      public void setUp() {
      try

      { DriverManager.registerDriver(new org.mariadb.jdbc.Driver()); connection = DriverManager.getConnection(URL, USER, PWD); connection.setAutoCommit(false); }

      catch (Exception e) {
      }
      }

      @After
      public void tearDown() {
      try

      { connection.commit(); connection.close(); }

      catch (Exception e) {
      }
      }

      @Test
      public void testStatement() throws Exception {
      final String sql = "SELECT id, start, end FROM time_period WHERE id=1;";
      Statement statement = connection.createStatement();
      ResultSet resultSet = statement.executeQuery(sql);
      while (resultSet.next())

      { System.out.println(resultSet.getInt(1)); System.out.println(resultSet.getTime(2));//OK and return 00:00:00 System.out.println(resultSet.getTime(3)); }

      resultSet.close();
      statement.close();
      }

      @Test
      public void testPreparedStatement() throws Exception {
      final String sql = "SELECT id, start, end FROM time_period WHERE id=?;";
      PreparedStatement preparedStatement = connection.prepareStatement(sql);
      preparedStatement.setInt(1, 1);
      ResultSet resultSet = preparedStatement.executeQuery();
      while (resultSet.next())

      { System.out.println(resultSet.getInt(1)); System.out.println(resultSet.getTime(2));//NOT OK retrun NULL when value=00:00:00 System.out.println(resultSet.getTime(3)); }

      resultSet.close();
      preparedStatement.close();
      }

      }

        Attachments

          Activity

            People

            Assignee:
            diego dupin Diego Dupin
            Reporter:
            cc Chun Chong
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.