Description:
If a stored procedure, with OUT or INOUT params, and a function with the same name exists, when registering the out parameters the following exception is thrown: «Exception in thread "main" java.sql.SQLException: Parameter number 1 is not an OUT parameter».
This only works in JDBC4+ and if the connection property 'getProceduresReturnsFunctions=false' is used.
How to repeat:
stmt.execute("DROP PROCEDURE IF EXISTS common_name");
stmt.execute("CREATE PROCEDURE common_name (INOUT param1 CHAR(20), IN param2 CHAR(20)) BEGIN SELECT CONCAT(param1, param2) INTO param1; END");
stmt.execute("DROP FUNCTION IF EXISTS common_name");
stmt.execute("CREATE FUNCTION common_name (param1 CHAR(20), param2 CHAR(20)) RETURNS CHAR(40) DETERMINISTIC RETURN CONCAT(param1, param2)");
CallableStatement cstmt = conn.prepareCall("{CALL common_name (?, ?)}");
cstmt.registerOutParameter(1, Types.CHAR);
cstmt.setString(1, "A");
cstmt.setString(2, "Z");
cstmt.execute();
Suggested fix:
Prevent fetching functions info when checking the parameters metadata.