java执行mysql存储过程_无法从Java执行MySQL存储过程

bd96500e110b49cbb3cd949968f18be7.png

I am connecting to a MySQL (5.08) database running on a linux machine from a web application running in tomcat.

I get the following exception when I try to execute a stored procedure:

com.hp.hpl.chaos.web.exception.DBException: getNextValue for operatorinstance[Additional Information from SQL Exception][SQLErrorCode: 0 SQLState: S1000

at com.hp.hpl.chaos.web.util.SQLUtil.getNextValue(SQLUtil.java:207)

..............

Caused by: 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:1619)

at com.mysql.jdbc.DatabaseMetaData.getProcedureColumns(DatabaseMetaData.java:4034)

at com.mysql.jdbc.CallableStatement.determineParameterTypes(CallableStatement.java:709)

at com.mysql.jdbc.CallableStatement.(CallableStatement.java:513)

at com.mysql.jdbc.Connection.parseCallableStatement(Connection.java:4583)

at com.mysql.jdbc.Connection.prepareCall(Connection.java:4657)

at com.mysql.jdbc.Connection.prepareCall(Connection.java:4631)

at com.hp.hpl.chaos.web.util.SQLUtil.getNextValue(SQLUtil.java:196)

... 17 more

After installing mysql on the machine. I have given the follwing grant options to root

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'pass';

Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;

Query OK, 0 rows affected (0.00 sec)

In the java class..

I am connecting to the db as follows:

String url = "jdbc:mysql://ipaddress:3306/test";

con = DriverManager.getConnection(url,"root", "pass");

I have also tried the url with the noAccessToProcedureBodies=true option included.

Can someone tell me what is wrong here? Is there anything I need to check?

解决方案

There are two ways to solve this:

set the connection's noAccessToProcedureBodies=true property

For example as part of the connection string:

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

The JDBC driver will then create "INOUT" strings for the arguments without requiring meta data like the exception says.

Grant SELECT privileges on mysql.proc to the database user

For example in the mysql prompt:

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

Of course this would allow the application to read the entire mysql.proc table that contains information about all stored procedures in all databases (including source code).

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值