Bug #61780 MySQL JDBC driver stops throwing SQLException in procedure metadata
Submitted: 7 Jul 2011 9:01 Modified: 5 Feb 2013 8:16
Reporter: Sunil John Email Updates:
Status: Not a Bug Impact on me:
None 
Category:Connector / J Severity:S2 (Serious)
Version:5.1.15 OS:Any
Assigned to: CPU Architecture:Any

[7 Jul 2011 9:01] Sunil John
Description:
Hi,
I was using MySQL JDBC driver 5.0.8. In that case if I try to call DatabaseMetaData.getProcedureColumns() for a invalid/non-existing stored procedure, an SQLException will be thrown.

This week we moved to 5.1.15 JDBC driver. Then onwards DatabaseMetaData.getProcedureColumns() is not throwing SQLException if procedureName is non existing.

My questions
1. Is it a behavioral change or is it a defect? Whats the expected behavior?
2. How we will distinguish between "valid procedure without any parameters" and "invalid stored procedures" when we use it in DatabaseMetaData.getProcedureColumns()

MySQL server : 5.0.67/5.1.46/5.5
OS:Windows

How to repeat:

public class TestMySQLJDBC {

	private final static String jdbcDriver ="com.mysql.jdbc.Driver";
	private final static String connectionUrl ="jdbc:mysql://cin0389:3306/testutf8";
	private final static String user = "root";
	private final static String password = "password";
	private final static String database = "testutf8";
	
	private final static String invalidStoredProcedure = "INVALID";
	
	private final static String validStoredProcedureWithoutParam = "TESTPROC";
	
	
	private Connection dbConnection;
	void createConnection() throws Exception{
		
		
			Class.forName(jdbcDriver);
			dbConnection = DriverManager.getConnection(connectionUrl, user, password);
			
	}
void getMetadataForInvalid() throws Exception{
		DatabaseMetaData metadata = null;
		ResultSet rs = null;
		boolean recordsPresent = false;
		try{ // trying metadata of invalid stored procedure	
			metadata = dbConnection.getMetaData();
			rs =metadata.getProcedureColumns(database, null, invalidStoredProcedure, null);
			System.out.println(rs.getString(1));
			System.out.println(rs.getString(2));
			System.out.println(rs.getString(3));
			while(rs.next()){
				recordsPresent = true;
				System.out.println(rs.getString(1));
				System.out.println(rs.getString(2));
				System.out.println(rs.getString(3));
			}
			if(!recordsPresent){
				System.out.println("Nothing is in resultset");
			}
		} finally{
			if(rs != null){
				try{
					rs.close();
				} catch(SQLException sqle){
					//ignore;
				}
			}
		}
		
	} 
void closeConnection(){
		try{
			if(dbConnection != null){
				dbConnection.close();
			}
		} catch(SQLException sqle){
			//ignore
		}
	}
	public static void main(String [] args){
		TestMySQLJDBC myTest = new TestMySQLJDBC();
		try {
			myTest.createConnection();
			myTest.getMetadataForValid();
		} catch(Exception e){
			System.out.println(e.getMessage());
		} finally{
			
			myTest.closeConnection();
		}
		
	}
	
}

Execute this using 5.0.8 driver and 5.1.15 driver. There is a change in way it behaves
[7 Jul 2011 9:14] Tonci Grgin
Hi Sunil and thanks for your report.

I can not remember right now if this is intentional but I'll check.
[5 Feb 2013 8:16] Tonci Grgin
Sorry, forgot about this. Specs say that getProcedureColumns should throw SQLException only in case of database access error. So this is compliant behavior.