Stored procedure call permission

JDBC connection executes MySQL stored procedure and reports permission error: User does not have access to metadata required to deter

[Summary: When executing a stored procedure, the following error occurs: java.sql.SQLException: User does not have access to metadata required to determine stored procedure parameter types. If rights can not be granted, configure connection with noAccessToProcedureBo] 
 

When executing the stored procedure, the following error occurs:

java.sql.SQLException: User does not have access to metadata required to determine stored procedure parameter types. If rights can not be granted, configure connection with "noAccessToProcedureBodies=true" to have driver generate parameters that represent INOUT strings irregardless of actual parameter types.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
at com.mysql.jdbc.DatabaseMetaData.getCallStmtParameterTypes(DatabaseMetaData.java:1616)
at com.mysql.jdbc.DatabaseMetaData.getProcedureColumns(DatabaseMetaData.java:4009)
at com.mysql.jdbc.CallableStatement.determineParameterTypes(CallableStatement.java:702)
at com.mysql.jdbc.CallableStatement.<init>(CallableStatement.java:513)
at com.mysql.jdbc.Connection.parseCallableStatement(Connection.java:4536)
at com.mysql.jdbc.Connection.prepareCall(Connection.java:4610)
at com.mysql.jdbc.Connection.prepareCall(Connection.java:4584)

After consulting the data, it is known that when JDBC calls the stored procedure, not only the user must have the execute authority, but also the access authority to mysql.proc. Otherwise it cannot access metadata. There are two workarounds:

 

1. Set a noAccessToProcedureBodies property for the database connection, the property value is true, the example is as follows:

 

  1. jdbc:mysql://ipaddress:3306/test?noAccessToProcedureBodies=true  

 

 It is said on the Internet that setting noAccessToProcedureBodies=true will have some effects (unverified):

 

1. When calling the stored procedure, there will be no type check, set to string type, and all parameters are set to int type, but when calling registerOutParameter, no exception is thrown.

2. The query result of the stored procedure cannot be obtained in the form of getXXX(String parameterName), but can only be obtained in the form of getXXX(int parameterIndex).

 

 

2. Empower the database user and grant the select permission to execute the mysql.proc table. The example is as follows:

 

  1. GRANT SELECT ON mysql.proc TO 'user'@'localhost';  

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326804341&siteId=291194637