java - How to call a MySQL stored procedure with multiple OUT parameters using JPA and Hibernate? -
i have following mysql stored procedure out parameters, how can call stored procedure through hibernate in out parameters?
create procedure dbname.getstatistics (out bigint unsigned, out b bigint unsigned, out c bigint unsigned) begin select count(*) dbname.table1 id =0; select count(*) b dbname.table2 id>0 , id<4; select count(*) c dbname.table3 id>4; end
edit
following code used in java test call of mysql stored procedure (with out parameters) through hibernate(java):
session session = hibernateutil.getsessionfactory().opensession(); connection connection = session.connection(); callablestatement callable = null; try { callable = connection.preparecall("{call dbname.getstatistics(?,?,?)}"); // 3 ?,?,? means 3 out parameter. // if parameters in type of // lets first 1 use : callable.setint(1, 10); callable.registeroutparameter(1, types.bigint); callable.registeroutparameter(2, types.bigint); callable.registeroutparameter(3, types.bigint); callable.executeupdate(); int value1 = callable.getint(1); int value2 = callable.getint(2); int value3 = callable.getint(3); system.out.println(value1); system.out.println(value2); system.out.println(value3); } catch (sqlexception e) { e.printstacktrace(); }
i don't think can hibernate. have seen done before
connection connection = session.connection(); callablestatement callable = null; callable = connection.preparecall("execute [procedure] ?"); callable.registeroutparameter(1, types.integer); callable.execute(); int id = callable.getint(1);
which has worked. see retrieving value stored procedure using native sql hibernate more context.
Comments
Post a Comment