zoukankan      html  css  js  c++  java
  • JDBC连接执行 MySQL 存储过程报权限错误:User does not have access to metadata required to determine stored procedure parameter types. If rights can not be granted,

    国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html
    内部邀请码:C8E245J (不写邀请码,没有现金送)
    国内私募机构九鼎控股打造,九鼎投资是在全国股份转让系统挂牌的公众公司,股票代码为430719,为中国PE第一股,市值超1000亿元。 

    ------------------------------------------------------------------------------------------------------------------------------------------------------------------

     

    执行存储过程时,出现如下错误:

    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,示例如下:

    Xml代码  收藏代码
    1. jdbc:mysql://ipaddress:3306/test?noAccessToProcedureBodies=true  

     网上说设置noAccessToProcedureBodies=true会带来一些影响(未经考证):

     

    1. 调用存储过程时,将没有类型检查,设为字符串类型,并且所有的参数设为int类型,但是在调用registerOutParameter时,不抛出异常。

    2. 存储过程的查询结果无法使用getXXX(String parameterName)的形式获取,只能通过getXXX(int parameterIndex)的方式获取。

    二.给数据库用户赋权,赋执行mysql.proc表的select权限,示例如下:

    Sql代码  收藏代码
    1. GRANT SELECT ON mysql.proc TO 'user'@'localhost';  

     

    参考资料:

    1. http://stackoverflow.com/questions/986628/mysql-java-cant-execute-stored-procedure
    2. http://space.itpub.net/18945822/viewspace-683363
    3. http://cau99.blog.51cto.com/1855224/348792
  • 相关阅读:
    ASP.NET中的状态保持(转载)
    Win7系统下VS2008安装SP1补丁解决JQuery无智能提示的问题
    合并多个List<T>类型并通过LINQ按指定属性排序
    ASP.NET状态保持:ViewState
    第一部分 CLR基础:第1章 CLR的执行模型
    Oracle存储过程知识汇总
    ASP.NET中Button控件的CommandName和CommandArgument属性用法
    PL/SQL Developer使用
    ASP.NET常用代码汇总
    PL/SQL Developer中文注释乱码的解决办法
  • 原文地址:https://www.cnblogs.com/AloneSword/p/3591702.html
Copyright © 2011-2022 走看看