I have implemented a code for calling stored procedure from hibernate. The sp returns a cursor, how do I get the result in List.
Below is my code for calling the sp. How to I create a list from callstm.getObject(1);
I'm using Oracle.
Transaction tx = sessionFactory.getCurrentSession().beginTransaction();
Session session = sessionFactory.getCurrentSession();
session.doReturningWork(new ReturningWork<Object>() {
@SuppressWarnings( "unchecked" )
@Override
public Object execute( Connection aConnection ) throws SQLException
{
CallableStatement callstm = null;
try
{
String functionCall = "{call PORTAL_PKG._pp_member_login(?, ?, ?, ? )}";
callstm = aConnection.prepareCall( functionCall );
callstm.registerOutParameter( 1, OracleTypes.CURSOR );
callstm.setString( 2, "Partner" );
callstm.setString( 3, "Member" );
callstm.setString( 4, "test@123" );
callstm.execute();
callstm.getObject(1);
}
finally
{
callstm.close();
}
}
});
Thanks in advance.
I think this should work.
...
callstm.execute();
ResultSet rset = (ResultSet)callstm.getObject(1);
while (rset.next()){
System.out.println(rset.getString(columnIndex));
}
// Close all the resources
...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.