Can't execute a MySQL stored procedure from Java

£可爱£侵袭症+ 提交于 2019-11-28 04:42:37

There are two ways to solve this:

  1. 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.

  2. 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).

Following steps worked for me in mysql

Step 1 : add follwong
Connection con = DriverManager.getConnection("jdbc:mysql://ipaddress:3306/logparser?noAccessToProcedureBodies = true ", "root", "");

Step 2 : GRANT ALL ON logparser.proc TO root@'%'; where logparser is DB name and proc is procedure name.

Running below queries should fix your issue.

GRANT <SELECT, CREATE, UPDATE, DELETE, ALL> PRIVILEGES ON mysql.proc TO '<user>'@'%';
FLUSH PRIVILEGES;

You can change the definer in the mysql.proc table to your database user.

select * from mysql.proc;

choose the stored proc that has problem and change the definer to 'yourdbuser'@'localhost'.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!