通过jdbc执行的存储过程

Org*_*rim 7 mysql stored-procedures jdbc

我在mysql数据库上创建了一些存储过程,但是当我尝试执行它们时,我得到:

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.
Run Code Online (Sandbox Code Playgroud)

我添加到我的连接字符串noAccessToProcedureBodies = true,但我仍然收到此消息.我使用DriverManager.getConnection(url,user,password)方法,我使用的是url

jdbc:mysql://[server-url]/[database-name]?noAccessToProcedureBodies=true 
Run Code Online (Sandbox Code Playgroud)

编辑:我的意思是我有一个名为creautenti的用户,我在此方法中用来创建新用户:

public static boolean creazioneUtente(String user, String password) throws EccezioneDaMostrare{
    if(apriConnessione(CREA_UTENTI_USER, CREA_UTENTI_PW, false)){
        try{
            conn.setAutoCommit(false);
            String sqlCommand="CREATE USER ? @'%' IDENTIFIED BY PASSWORD ?";
            String sqlCommandGrant="GRANT EXECUTE ON salvataggi.* TO ? REQUIRE SSL;";
            String sqlCommandGrantEx="GRANT SELECT ON `mysql`.`proc` TO ? @'%';";
            PreparedStatement s=conn.prepareStatement(sqlCommand);
            PreparedStatement sGrant=conn.prepareStatement(sqlCommandGrant);
            PreparedStatement sGrantEx=conn.prepareStatement(sqlCommandGrantEx);
            s.setString(1, user);
            sGrant.setString(1, user);
            sGrantEx.setString(1, user);
            s.setString(2, mySQLPASSWORD(password));
            s.execute();
            sGrant.executeUpdate();
            sGrantEx.executeUpdate();
            conn.commit();
            conn.setAutoCommit(true);
            chiudiConnessione();
            return true;
        }
        catch(SQLException e){
            try {
                conn.rollback();
            } catch (SQLException e1) {
                String msg=String.format("Errore durante la connessione al server MySQL:\n Messaggio:%s \n Stato SQL:%s \n Codice errore:%s", e.getMessage(), e.getSQLState(), e.getErrorCode());
                throw new EccezioneDaMostrare(msg);
            }
            chiudiConnessione();
            return false;
        }
    }
    else
        return false;
}
Run Code Online (Sandbox Code Playgroud)

(第一行只是打开与服务器的连接为creautenti,conn是Connection对象).所以我在服务器上以root身份登录,然后调用

GRANT SELECT ON `mysql`.`proc` TO 'creautenti'@'%' WITH GRANT OPTION;
Run Code Online (Sandbox Code Playgroud)

相应地更新了creautenti的特权,但是当我打电话时

GRANT SELECT ON `mysql`.`proc` TO '<username>'@'%';
Run Code Online (Sandbox Code Playgroud)

以任何其他用户身份登录为creautenti,不会修改权限.所有例程都在salvataggi中,我给每个用户提供EXECUTE权限,所以我认为这也不是问题所在.

Tom*_*Mac 4

您最好实际上mysql.proc向应用程序用户授予对表的访问权限。因此,以 root 身份连接到 MySQL 数据库并运行以下命令:

GRANT SELECT ON `mysql`.`proc` TO '<username>'@'%';
Run Code Online (Sandbox Code Playgroud)

然后,您的 Java 应用程序应该能够看到正确的元数据,而无需指定noAccessToProcedureBodies=true

还要确保连接数据库的用户对相关过程具有执行权限。同样,作为 root 用户或具有授予权限的用户:

GRANT EXECUTE ON PROCEDURE db.storedproc TO '<username>'@'%';
Run Code Online (Sandbox Code Playgroud)

祝你好运!