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

Missing leading zeros when fetching String values from numeric columns with zerofill

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 1.3.7, 1.4.6, 1.5.8
    • 1.5.9
    • Other
    • None

    Description

      If we use the getString() method to get the value from a ResultSet for a integer column with the zerofill option the value we obtain doesn't have the expected leading zeros.
      We can reproduce the behavior with the next snippet:
      {
      Connection connection = DriverManager.getConnection (connectionString, user, password);

      Statement st = connection.createStatement();
      st.executeUpdate("drop table if exists tmpTest;");
      st.executeUpdate("create table tmpTest (id int unsigned primary key auto_increment, value smallint(3) unsigned zerofill not null unique);");
      st.executeUpdate("insert into tmpTest(value) values (1), (4), (5), (8);");

      PreparedStatement pst1 = connection.prepareStatement("select value from tmpTest");
      ResultSet rs1 = pst1.executeQuery();
      while(rs1.next())

      { System.out.println("Value: " + rs1.getString("value")); }

      rs1.close();
      pst1.close();

      st.close();
      connection.close();
      }

      Using the 1.1.8 or 1.2.3 versions of the connector this returns the expected result:
      Value: 001
      Value: 004
      Value: 005
      Value: 008

      In any version after 1.3.0 the behavior changes:
      Value: 1
      Value: 4
      Value: 5
      Value: 8

      Attachments

        Activity

          People

            diego dupin Diego Dupin
            fgarciau Francisco Javier Garcia Urtiaga
            Votes:
            0 Vote for this issue
            Watchers:
            1 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.