JDBC Connection execution MySQL stored procedure report permission error

Source: Internet
Author: User

To execute a stored procedure in Java by using JDBC to connect to MySQL times error:

16:41:16,095 ERROR [Org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (ajp--0.0.0.0-8009-3) User does not has access To metadata required to determine stored procedure parameter types. If rights can not is granted, configure connection with "Noaccesstoprocedurebodies=true" to has driver generate parameter s that represent INOUT strings irregardless of actual parameter types.16:41:16,111 ERROR [stderr] (ajp--0.0.0.0-8009-3) or G.hibernate.exception.genericjdbcexception:error executing work 16:41:16,111 error [stderr] (ajp--0.0.0.0-8009-3) at Org.hibernate.exception.internal.StandardSQLExceptionConverter.convert (standardsqlexceptionconverter.java:54) 16:41:16,111 ERROR [stderr] (ajp--0.0.0.0-8009-3) at Org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert ( sqlexceptionhelper.java:124) 16:41:16,111 ERROR [stderr] (ajp--0.0.0.0-8009-3) at Org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert (sqlexceptionhelper.java:109) 16:41:16,111 ERROR [stderr] (ajp--0.0.0.0-8009-3) at Org.hibernaTe.engine.jdbc.internal.JdbcCoordinatorImpl.coordinateWork (jdbccoordinatorimpl.java:298) 16:41:16,111 ERROR [ STDERR] (ajp--0.0.0.0-8009-3) at Org.hibernate.internal.SessionImpl.doWork (sessionimpl.java:1925) 16:41:16,111 ERROR [stderr] (ajp--0.0.0.0-8009-3) at Org.hibernate.internal.SessionImpl.doWork (sessionimpl.java:1911)

  

After consulting the data, JDBC calls the stored procedure not only for the user to have Execute permission, but also to have access to mysql.proc. Otherwise it cannot access the metadata. There are two ways to resolve this:

One. To set a Noaccesstoprocedurebodies property for a database connection, the property value is true, as shown in the following example:

Jdbc:mysql://ipaddress:3306/test?noaccesstoprocedurebodies=true

Online says setting up Noaccesstoprocedurebodies=true will bring some impact (not verified):

1. When a stored procedure is called, no type checking is set to the string type, and all arguments are set to the int type, but no exception is thrown when Registeroutparameter is called.

2. The query results of a stored procedure cannot be obtained using GETXXX (String parametername) and can only be obtained by getxxx (int parameterindex).

Two. Empower the database user to perform SELECT permissions for the Mysql.proc table, as shown in the following example:

GRANT SELECT on Mysql.proc to ' user ' @ ' localhost ';

Resources:

    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

JDBC Connection execution MySQL stored procedure report permission error

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.