public List < List < String > > doSelect ( final String sql ) throws SQLException { List < List < String >> results = new ArrayList < List < String > > ( ) ; LOG . info ( "Connecting to: " + this . dbString + " with " + this . usr + " and " + this . pwd ) ; LOG . info ( "Executing: " + sql ) ; Connection connection = null ; Statement st = null ; ResultSet rs = null ; try { connection = DriverManager . getConnection ( this . dbString , this . usr , this . pwd ) ; st = connection . createStatement ( ) ; rs = st . executeQuery ( sql ) ; while ( rs . next ( ) ) { ResultSetMetaData meta = rs . getMetaData ( ) ; List < String > lines = new ArrayList < String > ( ) ; for ( int col = 1 ; col < meta . getColumnCount ( ) + 1 ; col ++ ) { lines . add ( rs . getString ( col ) ) ; } results . add ( lines ) ; } } finally { if ( rs != null ) { rs . close ( ) ; } if ( st != null ) { st . close ( ) ; } if ( connection != null ) { connection . close ( ) ; } } LOG . info ( "Result returned after running " + sql + " is: " + results ) ; return results ; }
Runs a select query against the DB and get the results in a list of lists . Each item in the list will be a list of items corresponding to a row returned by the select .