Bug #40489 MySQL Connector/J fails to return parameter type
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.
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.053 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.
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.