標籤:blog http io ar os 使用 sp java strong
JDBC串連執行 MySQL 預存程序報許可權錯誤:User does not have access to metadata required to determine stored procedure parameter types. If rights can not be granted,
執行預存程序時,出現如下錯誤:
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)
經過查閱資料得知,JDBC在調用預存程序時不光使用者要有execute的許可權,還需要對mysql.proc具有存取權限。否則它無法訪問metadata。有兩種解決方案:
一.給資料庫連接設定一個noAccessToProcedureBodies屬性,屬性值為true,樣本如下:
- jdbc:mysql://ipaddress:3306/test?noAccessToProcedureBodies=true
網上說設定noAccessToProcedureBodies=true會帶來一些影響(未經考證):
1. 調用預存程序時,將沒有類型檢查,設為字串類型,並且所有的參數設為int類型,但是在調用registerOutParameter時,不拋出異常。
2. 預存程序的查詢結果無法使用getXXX(String parameterName)的形式擷取,只能通過getXXX(int parameterIndex)的方式擷取。
二.給資料庫使用者賦權,賦執行mysql.proc表的select許可權,樣本如下:
- GRANT SELECT ON mysql.proc TO ‘user‘@‘localhost‘;
原文地址:http://www.cnblogs.com/AloneSword/p/3591702.html
JDBC使用MySQL預存程序錯誤