private CommandOutput < ? , ? > executeSql ( List < Command > cmds ) { String query = null ; int fetchSize = 0 ; for ( Command cmd : cmds ) { if ( cmd instanceof JdbcCommand ) { JdbcCommandType type = ( JdbcCommandType ) cmd . getCommandType ( ) ; switch ( type ) { case QUERY : query = cmd . getParams ( ) . get ( 0 ) ; break ; case FETCHSIZE : fetchSize = Integer . parseInt ( cmd . getParams ( ) . get ( 0 ) ) ; break ; default : this . log . error ( "Command " + type . toString ( ) + " not recognized" ) ; break ; } } } this . log . info ( "Executing query:" + query ) ; ResultSet resultSet = null ; try { this . jdbcSource = createJdbcSource ( ) ; if ( this . dataConnection == null ) { this . dataConnection = this . jdbcSource . getConnection ( ) ; } Statement statement = this . dataConnection . createStatement ( ) ; if ( fetchSize != 0 && this . getExpectedRecordCount ( ) > 2000 ) { statement . setFetchSize ( fetchSize ) ; } final boolean status = statement . execute ( query ) ; if ( status == false ) { this . log . error ( "Failed to execute sql:" + query ) ; } resultSet = statement . getResultSet ( ) ; } catch ( Exception e ) { this . log . error ( "Failed to execute sql:" + query + " ;error-" + e . getMessage ( ) , e ) ; } CommandOutput < JdbcCommand , ResultSet > output = new JdbcCommandOutput ( ) ; output . put ( ( JdbcCommand ) cmds . get ( 0 ) , resultSet ) ; return output ; }
Execute query using JDBC simple Statement Set fetch size