Bug #118201 A potential bug in Mysql Connector/J
Submitted: 15 May 2:37 Modified: 16 May 23:59
Reporter: 策 吕 Email Updates:
Status: Analyzing Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:9.0.0 OS:Any
Assigned to: CPU Architecture:Any

[15 May 2:37] 策 吕
Description:
The following inconsistent result occurs when using MYSQL Connector, but I don't have the following problem when using OceanBase Connector.

1. When allowMultiQueries is set to true, the result is printed:
----------------
 * 267492252 * 
----------------

2. When allowMultiQueries is set to false, the result is printed:
----------------
* 622 * 
* 267492252 * 
----------------

How to repeat:
import java.sql.*;

public class test {
    public static void main(String[] args) throws SQLException
    {
        
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?user=root&password=1234&allowMultiQueries=true");

        Statement stmt = con.createStatement();
        
        // First: create table
        stmt.execute("DROP TABLE IF EXIST t0");
        stmt.execute("CREATE TABLE t0(c0 INT PRIMARY KEY NOT NULL)");
        
        // Second: randomly insert an integer of type INT
        stmt.execute("INSERT INTO t0 VALUES (267492252)");

        // Third: Inserting random integers using batch operations
        Statement bstmt = con.createStatement();
        bstmt.addBatch("INSERT INTO t0 VALUES (267492252)");
        bstmt.addBatch("INSERT INTO t0 VALUES (622)");

        // ..., Here you can add some more addBatch(String sql) methods.

        try {
            bstmt.executeBatch();
        } catch (Exception e) {
           
        }
        
        // Fourth: execute "SELECT * FROM t0" and print the result.
        executeAndPrint(con, "SELECT * FROM t0");
    }
    public static void executeAndPrint(Connection con, String sql) {
        try (Statement statement = con.createStatement()) {
            if (statement.execute(sql)) {
                ResultSet rs = statement.getResultSet();
                ResultSetMetaData rsMetaData = rs.getMetaData();
                int count = rsMetaData.getColumnCount();
                while (rs.next()) {
                    for (int i = 1; i <= count; i++) {
                        System.out.print("* " + rs.getString(i) + " * ");
                    }
                    System.out.println();
                }
            } else {
                System.out.println("Update count: " + statement.getUpdateCount());
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}