JDBC使用MySQL預存程序錯誤

來源:互聯網
上載者:User

標籤: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,樣本如下:

 

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

 

 網上說設定noAccessToProcedureBodies=true會帶來一些影響(未經考證):

 

1. 調用預存程序時,將沒有類型檢查,設為字串類型,並且所有的參數設為int類型,但是在調用registerOutParameter時,不拋出異常。

2. 預存程序的查詢結果無法使用getXXX(String parameterName)的形式擷取,只能通過getXXX(int parameterIndex)的方式擷取。

 

 

二.給資料庫使用者賦權,賦執行mysql.proc表的select許可權,樣本如下:

 

  1. GRANT SELECT ON mysql.proc TO ‘user‘@‘localhost‘;  
原文地址:http://www.cnblogs.com/AloneSword/p/3591702.html

JDBC使用MySQL預存程序錯誤

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.