static < T > List < T > executeOraBlock ( Connection connection , String sql , Class < T > clazz , List < SqlParam > sqlParams ) throws SQLException { String cursorParam = null ; List < T > list = new ArrayList < T > ( ) ; //boolean autoCommitOrig = connection.getAutoCommit(); //if (autoCommitOrig == true) { // connection.setAutoCommit(false); // to able to read from temp-tables //} CallableStatement stmt = null ; ResultSet resultSet = null ; try { stmt = connection . prepareCall ( sql ) ; cursorParam = stmtAssignSqlParams ( stmt , sqlParams ) ; boolean hasRs = stmt . execute ( ) ; if ( cursorParam != null ) { resultSet = ( ResultSet ) stmt . getObject ( cursorParam ) ; list = resultSetToList ( resultSet , clazz ) ; } } finally { try { if ( resultSet != null ) resultSet . close ( ) ; } catch ( Exception e ) { logger . error ( "Cannot close resultSet" , e ) ; } ; //if (autoCommitOrig == true) // connection.setAutoCommit(autoCommitOrig); try { if ( stmt != null ) stmt . close ( ) ; } catch ( Exception e ) { logger . error ( "Cannot close statement" , e ) ; } ; } return list ; }
Execute sql block or stored procedure . If exists output parameter with type CURSOR then return resultSet as List of clazz type objects .