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

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.3.7, 1.4.6, 1.5.8
    • Fix Version/s: 1.5.9
    • Component/s: Other
    • Labels:
      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

            Assignee:
            diego dupin Diego Dupin
            Reporter:
            fgarciau Francisco Javier Garcia Urtiaga
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: