Search code examples
javajtablejtableheader

I have filled my jtable using following code but i m not able to set header of the column of the table


ResultSet rs = statment.executeQuery();
table.setModel(DbUtils.resultSetToTableModel(rs));

Solution

  • I think you cannot set column names which are selected from a database, but you can copy data out of that column in a new column and set the name of that new column.

    Or else you can get that column name using this code.. :)

    ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM TABLE2");
    ResultSetMetaData rsmd = rs.getMetaData();
    String name = rsmd.getColumnName(1);
    

    Where 1 is the index of the column.