Here is an easy way to convert a Java ResultSet to a TableModel, from which you can create a JTable thus:

JTable t = new JTable(DbUtils.resultSetToTableModel(rs));

If you only need a List of List, you can call

java.util.List listOfList = net.proteanit.sql.DbUtils.resultSetToNestedList(rs); 

The jar is HERE (add it to your classpath to use it), and it includes source. You need to import net.proteanit.sql.DbUtils if using the DbUtils below from the jar


import java.sql.ResultSet;
import java.sql.ResultSetMetaData;

import java.util.Vector;

import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

public class DbUtils {
    public static TableModel resultSetToTableModel(ResultSet rs) {
        try {
            ResultSetMetaData metaData = rs.getMetaData();
            int numberOfColumns = metaData.getColumnCount();
            Vector columnNames = new Vector();

            // Get the column names
            for (int column = 0; column < numberOfColumns; column++) {
                columnNames.addElement(metaData.getColumnLabel(column + 1));

            // Get all rows.
            Vector rows = new Vector();

            while ( {
                Vector newRow = new Vector();

                for (int i = 1; i <= numberOfColumns; i++) {


            return new DefaultTableModel(rows, columnNames);
        } catch (Exception e) {

            return null;

Please support this site using the button below: