Description:
This is the javadoc description of argument 'catalog' to
java.sql.DatabaseMetaData.getIndexInfo() in Sun JDK 1.4.2 and 1.5.0:
catalog - a catalog name; must match the catalog name as it is stored in this database; ""
retrieves those without a catalog; null means that the catalog name should not be used to
narrow the search
But looking at the 3.1.10 source code of com.mysql.jdbc.DatabaseMetaData, that is not how
it is implemented:
if (catalog != null) {
if (!catalog.equals("")) {
databasePart = " FROM " + this.quotedId + catalog
+ this.quotedId;
}
} else {
if (!this.conn.getNullCatalogMeansCurrent()) {
throw new SQLException("'catalog' parameter can not be null",
SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
}
catalog = this.database;
databasePart = " FROM " + this.quotedId + this.database
+ this.quotedId;
}
Without any detailed knowledge of the code above, it looks to me that "" is treated the
way null should have been -- and null is handled just wrong.
How to repeat:
Use null or "" as catalog argument to com.mysql.jdbc.DatabaseMetaData.getIndexInfo().
DatabaseMetaData dmd = ...;
dmd.getIndexInfo(null, null, <tablename>, false, true);
dmd.getIndexInfo("", null, <tablename>, false, true);
Suggested fix:
Use catalog argument according to official Sun javadoc of java.sql.DatabaseMetaData.
Description: This is the javadoc description of argument 'catalog' to java.sql.DatabaseMetaData.getIndexInfo() in Sun JDK 1.4.2 and 1.5.0: catalog - a catalog name; must match the catalog name as it is stored in this database; "" retrieves those without a catalog; null means that the catalog name should not be used to narrow the search But looking at the 3.1.10 source code of com.mysql.jdbc.DatabaseMetaData, that is not how it is implemented: if (catalog != null) { if (!catalog.equals("")) { databasePart = " FROM " + this.quotedId + catalog + this.quotedId; } } else { if (!this.conn.getNullCatalogMeansCurrent()) { throw new SQLException("'catalog' parameter can not be null", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); } catalog = this.database; databasePart = " FROM " + this.quotedId + this.database + this.quotedId; } Without any detailed knowledge of the code above, it looks to me that "" is treated the way null should have been -- and null is handled just wrong. How to repeat: Use null or "" as catalog argument to com.mysql.jdbc.DatabaseMetaData.getIndexInfo(). DatabaseMetaData dmd = ...; dmd.getIndexInfo(null, null, <tablename>, false, true); dmd.getIndexInfo("", null, <tablename>, false, true); Suggested fix: Use catalog argument according to official Sun javadoc of java.sql.DatabaseMetaData.