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:
- Http://stackoverflow.com/questions/986628/mysql-java-cant-execute-stored-procedure
- http://space.itpub.net/18945822/viewspace-683363
- http://cau99.blog.51cto.com/1855224/348792
JDBC Connection execution MySQL stored procedure report permission error