java - Hibernate 4 - Call stored procedure having IN as well as OUT parameters -
i researched how call stored procedure using hibernate 4 session object in & out params, no use.
finally got clue related "sessionimpl". using object can connection object.
using connection object can call preparecall() method, support in/out params of procedure.
following sample snippet.
map<string, string> returnmap = new hashmap<string, string>(); session session = sessionfactory.getcurrentsession(); connection connobj = ((sessionimpl)session).connection(); callablestatement connstmt = connobj.preparecall("{ call schema.pkg_name.sp_name(?,?,?) }"); connstmt.setlong(1, 123456); connstmt.registeroutparameter(2, java.sql.types.varchar); connstmt.registeroutparameter(3, java.sql.types.varchar); connstmt.execute(); if(connstmt != null && connstmt.getstring(2).equalsignorecase("y")) { returnmap.put("returnid", exceptionconstants.success_status); returnmap.put("returnmessage", connstmt.getstring(3)); } else { returnmap.put("returnid", exceptionconstants.failed_status); returnmap.put("returnmessage", connstmt.getstring(3)); }
Comments
Post a Comment