Bug #40489 MySQL Connector/J fails to return parameter type
Submitted: 4 Nov 2008 6:54 Modified: 5 Nov 2008 11:02
Reporter: Naveen K Email Updates:
Status: Can't repeat Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:5.1.5 OS:Windows (XP SP2)
Assigned to: CPU Architecture:Any
Tags: Parameter, parametertype

[4 Nov 2008 6:54] Naveen K
Description:
I tried the following java code snippet with a MySQL installation. The parameter type for the preparedstatement is not returned.

Class.forName("com.mysql.jdbc.Driver");
Connection con1 = DriverManager.getConnection("jdbc:mysql://129.158.238.234:3306/demo", "root", "root");
PreparedStatement ps1 = con1.prepareStatement("update flight_info set flight_no=?,airline_id=?,destination=?,departure_date=?,departure_time=?;");
ParameterMetaData paramMetaData1 = (MysqlParameterMetadata)ps1.getParameterMetaData();
for (int i = 0; i < paramMetaData1.getParameterCount(); i++) {
System.out.println(paramMetaData1.getParameterType(i + 1) + ":" + paramMetaData1.getParameterTypeName(i + 1));
}

(I made sure such a table with the given columns are there in the database!)

The connector/J version I used is 5.1.5. This fails with

java.sql.SQLException: Parameter metadata not available for the given statement
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1056)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
at com.mysql.jdbc.MysqlParameterMetadata.checkAvailable(MysqlParameterMetadata.java:68)
at com.mysql.jdbc.MysqlParameterMetadata.getParameterType(MysqlParameterMetadata.java:117)

How to repeat:
This can be tried with a simple standalone as follows:

Class.forName("com.mysql.jdbc.Driver");
Connection con1 = DriverManager.getConnection("jdbc:mysql://129.158.238.234:3306/demo", "root", "root");
PreparedStatement ps1 = con1.prepareStatement("update flight_info set flight_no=?,airline_id=?,destination=?,departure_date=?,departure_time=?;");
ParameterMetaData paramMetaData1 = (MysqlParameterMetadata)ps1.getParameterMetaData();
for (int i = 0; i < paramMetaData1.getParameterCount(); i++) {
System.out.println(paramMetaData1.getParameterType(i + 1) + ":" + paramMetaData1.getParameterTypeName(i + 1));
}

Suggested fix:
I see that there's a class MysqlparameterMetaData in the jar but this doesn't seem to return parameter types.
[5 Nov 2008 11:02] Tonci Grgin
Hi Naveen and thanks for your report.

I am unable to repeat it as it was fixed since Bug#10310.
Please see proper way to code this in regression test suite,
CallableStatementRegressionTest.java, Ln. 467.

Please inform me of outcome. Does regression test passes on your box?