Bug #110586 got unexpected result when the data type was set to ZEROFILL
Submitted: 3 Apr 2023 6:42 Modified: 4 Apr 2023 10:58
Reporter: Wenqian Deng Email Updates:
Status: Verified Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:8.0.32 OS:Any
Assigned to: CPU Architecture:Any

[3 Apr 2023 6:42] Wenqian Deng
Description:
I use MySQL Connector J 8.0.32 and MySQL 5.7. When I use ZEROFILL to create a new table and ResultSet.getString() to get the results of a SELECT query, I find that the results are not zero-filled. 
However, I also use MariaDB Connector J and the command line client tool and they both return zero-filled results.
For example, in the provided test case, the expected result is: `0000023987`, but the actual value is `23987`.

How to repeat:
@Test
public void test() throws SQLException {
    String url = "jdbc:mysql://localhost:3306?user=user&password=password";
    Connection con = DriverManager.getConnection(url);

    execute(con, "DROP DATABASE IF EXISTS test");
    execute(con, "CREATE DATABASE test");
    execute(con, "USE test");
    execute(con, "CREATE TABLE IF NOT EXISTS t0(c0 INTEGER ZEROFILL)");
    execute(con, "INSERT INTO t0 VALUES(23987)");

    Statement stmt = con.createStatement();
    if (stmt.execute("SELECT * FROM t0")) {
        ResultSet rs = stmt.getResultSet();
        ResultSetMetaData rsMetaData = rs.getMetaData();
        int count = rsMetaData.getColumnCount();
        StringBuffer sb = new StringBuffer();

        while (rs.next()) {
            sb.setLength(0);
            for (int i = 1; i <= count; i++) {
                sb.append("* " + rs.getString(i) + " *");
            }
            System.out.println(sb);
        }
    }
}

public void execute(Connection con, String sql)  {
    try {
        Statement statement = con.createStatement();
        statement.execute(sql);
        statement.close();
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
[4 Apr 2023 10:58] MySQL Verification Team
Hello Wenqian Deng,

Thank you for the report and test case.

regards,
Umesh