Bug #8803 DataBaseMetaData.getBestRowIdentifier ResultSet fails on getInt("DATA_TYPE");

Submitted: 25 Feb 2005 9:32 Modified: 18 Mar 2005 18:34
Reporter: Johannes Poulsen Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S2 (Serious)
Version:3.1.7 OS:Windows (Windows 2000)
Assigned to: Mark Matthews CPU Architecture:Any

[25 Feb 2005 9:32] Johannes Poulsen
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
[18 Mar 2005 18:34] Mark Matthews
Fixed for 3.1.8. Thanks for your bug report.

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.038 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.