Description:
The Connector/J version 3.1.7 and version 3.2.0 Alpha throws a java.lang.ArrayIndexOutOfBoundsException when querying the ResultSet returned by DatabaseMetaData.getBestRowIdentifier(...) for the getInt("DATA_TYPE").
The MySQL Server is version 4.1.10-nt.
The same code worked with mysql-connector-java-3.0.7-stable-bin.jar and a 4.0.something database.
Stacktrace from the attached program:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at com.mysql.jdbc.StringUtils.getInt(StringUtils.java:841)
at com.mysql.jdbc.ResultSet.parseIntWithOverflowCheck(ResultSet.java:1354)
at com.mysql.jdbc.ResultSet.getInt(ResultSet.java:1246)
at com.mysql.jdbc.ResultSet.getInt(ResultSet.java:1498)
at Test.testMetadata(Test.java:17)
at Test.main(Test.java:29)
How to repeat:
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
public class Test {
public void testMetadata() throws ClassNotFoundException, SQLException {
Class.forName("com.mysql.jdbc.Driver");
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql?user=root&password=myPassword");
DatabaseMetaData metadata = connection.getMetaData();
ResultSet bestRowIdentifiers = metadata.getBestRowIdentifier("mysql", null, "db", DatabaseMetaData.bestRowNotPseudo, true);
while (bestRowIdentifiers.next()) {
bestRowIdentifiers.getShort("SCOPE");
bestRowIdentifiers.getString("COLUMN_NAME");
bestRowIdentifiers.getInt("DATA_TYPE"); // **** Fails here *****
bestRowIdentifiers.getString("TYPE_NAME");
bestRowIdentifiers.getInt("COLUMN_SIZE");
bestRowIdentifiers.getInt("BUFFER_LENGTH");
bestRowIdentifiers.getShort("DECIMAL_DIGITS");
bestRowIdentifiers.getShort("PSEUDO_COLUMN");
}
System.out.println("testMetadata() Done");
}
public static void main(String[] args) throws ClassNotFoundException, SQLException {
Test test = new Test();
test.testMetadata();
}
}
Suggested fix:
No suggestions