Description:
I have identified that when executing certain non-DML SQL statements (e.g., DESC t0) via Statement.executeBatch(), the MySQL Connector/J driver returns -1 in the update-counts array. According to the JDBC specification, the only valid return values are:
* A non-negative integer (number of rows affected)
* Statement.SUCCESS_NO_INFO (-2)
* Statement.EXECUTE_FAILED (-3)
Source link: https://docs.oracle.com/javase/7/docs/api/java/sql/Statement.html
How to repeat:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class test110325bugMO {
public static void main(String[] args) throws SQLException {
String url1 = "jdbc:mysql://localhost:3306/test?user=root&password=1234&allowMultiQueries=true";
String url2 = "jdbc:oceanbase://49.52.27.61:2881/test?user=root@test&password=1234&allowMultiQueries=true";
Connection con = null;
con = DriverManager.getConnection(url1);
Statement statement = con.createStatement();
statement.execute("DROP DATABASE IF EXISTS test;");
statement.execute("CREATE DATABASE test;");
statement.execute("USE test;");
statement.execute("CREATE TABLE t0(c0 SMALLINT NOT NULL);");
//statement.addBatch("REPAIR TABLE t0");
statement.addBatch("DESC t0");
int[] res = statement.executeBatch();
for (int r : res) {
System.out.println(r);
}
statement.close();
}
}