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

StackOverflow https://stackoverflow.com/questions/19008037

  •  29-06-2022
  •  | 
  •  

Question

ResultSet rs = statment.executeQuery();
table.setModel(DbUtils.resultSetToTableModel(rs));
Was it helpful?

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top