stmt pointer is closed when sorting resultSet metadata
13:17 21 May 2026

I am creating a Swing program that runs a query on a database, then produces a JTable out of the resultset. When I try to run it, I get stmt pointer is closed in my console. This happens when it reaches the line

JTable table = new JTable(DBTable.buildTableModel(results));

Here is DBTable.buildTableModel():

public class DBTable{
    
    public static DefaultTableModel buildTableModel(ResultSet results)
            throws SQLException {

        ResultSetMetaData metaData = results.getMetaData();
        Vector columnNames = new Vector();
        int columnCount = metaData.getColumnCount();
        for (int column = 1; column <= columnCount; column++) {
            columnNames.add(metaData.getColumnName(column));
        }
        Vector> data = new Vector>();
        while (results.next()) {
            Vector vector = new Vector();
            for (int columnIndex = 1; columnIndex <= columnCount; columnIndex++) {
                vector.add(results.getObject(columnIndex));
            }
            data.add(vector);
        }
        return new DefaultTableModel(data, columnNames);

    }

}

It is this line specifically that causes the issue, and it doesnt make it past it even on the first loop:

columnNames.add(metaData.getColumnName(column));

Can anyone tell me why this is?

java database swing