mysqlconnector-j

Does MYSQL (via Connector/J) support named parameters?


I'm reading MYSQL refman-5.6.pdf. I'm quite puzzled.

The mysql_stmt_bind sample code shows only ? sytnax. Meanwhile the Connector/J sample has this:

//
// Alternatively, set a parameter using
// the parameter name
//
cStmt.setString("inputParameter", "abcdefg");

If the named parameter is not an extended function of Connector/J, what is the correct syntax for MYSQL named parameter?


Solution

  • http://dev.mysql.com/doc/refman/5.6/en/connector-j-usagenotes-statements-callable.html#connector-j-examples-callablestatement has the example you are referring to, and it says:

    CallableStatement also supports setting parameters by name:

    So this is specific to CallableStatement which is used for invoking stored procedures, and it's specific to MySQL's JDBC implementation. This is not standard for the JDBC spec.

    This extension has been implemented only for CallableStatement, not for PreparedStatement.


    Re your comment:

    Yes, that's correct, MySQL does not support named parameters, only positional parameters.

    Client interfaces like Connector/J CallableStatement and PHP's PDO library actually have to do some extra work to mimic named parameters.