[ACCEPTED]-How to convert ResultSet into Object[] and retrieve the data-jdbc

Accepted answer
Score: 11

For whatever weird reasons you need this. Here 8 is how:

List<object[]> records=new ArrayList<object[]>();
while(resultSet.next()){
    int cols = resultSet.getMetaData().getColumnCount();
    Object[] arr = new Object[cols];
    for(int i=0; i<cols; i++){
      arr[i] = resultSet.getObject(i+1);
    }
    records.add(arr);
}

My 2 cents:

Ideally, you will have an proper 7 object that maps Table columns to Java object 6 fields. Instead of using an array of objects, you 5 will set the properties to the POJO or Value 4 Object (VO) and return the list of object. That 3 is much simpler and makes more sense. You 2 may want to revisit your design if you have 1 to live on list of Object array!

More Related questions