public void addRows ( ResultSet rs ) throws SQLException { ResultSetMetaData rsmd = rs . getMetaData ( ) ; int columnCount = rsmd . getColumnCount ( ) ; while ( rs . next ( ) ) { Map < String , Object > row = new HashMap < String , Object > ( ) ; for ( int i = 1 ; i < columnCount + 1 ; i ++ ) { String colName = rsmd . getColumnName ( i ) ; Object colObj = rs . getObject ( i ) ; if ( colObj == null ) { // avoid error if trying to convert data types row . put ( colName , colObj ) ; } else { if ( colObj instanceof oracle . sql . Datum ) { colObj = ( ( oracle . sql . TIMESTAMP ) colObj ) . toJdbc ( ) ; } if ( colObj instanceof java . sql . Timestamp ) { row . put ( colName , new Date ( ( ( java . sql . Timestamp ) colObj ) . getTime ( ) ) ) ; } else if ( colObj instanceof java . sql . Date ) { row . put ( colName , new Date ( ( ( java . sql . Date ) colObj ) . getTime ( ) ) ) ; } else { row . put ( colName , colObj ) ; } } } addRow ( row ) ; } }
Add rows from a JDBC ResultSet . Each row will be a HashMap mapped from a record of ResultSet .