JDBC連接mysql提示noAccessToProcedureBodies=true

出現的問題:
ERROR, Thread-4, com.adwo.test.db.DBOpt, 2017-03-07 10:05:38,773, - ,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.

解釋:
   這是因爲jdbc調用存儲過程時需要有show create procudure權限或是有表mysql.proc的select的權限

解決方法:
1.通過在jdbc連接屬性中設置noAccessToProcedureBodies=true(默認是false)。但是加該參數會有影響
- 調用存儲過程時,將沒有類型檢查,設爲字符串類型,並且所有的參數設爲in類型,但是在調用registerOutParameter時,不拋出異常
- 存儲過程的查詢結果無法使用getXXX(String parameterName)的形式獲取,只能通過getXXX(int parameterIndex)的方式獲取

2.參考https://lists.mysql.com/commits/17817 修改

3.給mysql 普通用戶授予相應的權限

#%可以換localhost或者127.0.0.1,看自己的情況而定
grant Select on mysql.proc to 'user'@%
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章