Tuesday, June 15, 2010

Executing a Callable Statement using DBTransaction

Rather than creating a new Application Module and then bind it to new DBTransaction, to execute a query or return the result of a procedure "which would create a new connection to database".

You can use the following code snippet to create a callable statement to execute a database procedure and get results out in resultSet:

BindingContext bindingContext = 

ApplicationModuleImpl amimpl=
DBTransaction trans=amimpl.getDBTransaction();
CallableStatement cs = trans.createCallableStatement("{call ? :=
     NAME_OF_PROCEDURE(?,?) }",trans.DEFAULT);
cs.registerOutParameter(1, Types.VARCHAR);       
cs.setString(2, searchstring);       
cs.setString(3, "");

return cs.getString(1);