Hi. i made a database table table and i showed it in a jframe through jtable.I want to change my column name displayed.So far i used the follwing code.

private void Update_table(){
String sql="select stu_id ,stu_name ,Blood_group  from student";
md = rs.getMetaData();
int columnCount = md.getColumnCount();

Vector data = new Vector(columnCount);
Vector row = new Vector(columnCount);
Vector columnNames = new Vector(columnCount);

for (int i = 1; i <= columnCount; i++) {
while (rs.next()) {
    for (int i = 1; i <= columnCount; i++) {

    row = new Vector(columnCount); // Create a new row Vector
DefaultTableModel model = new DefaultTableModel(data, columnNames);

table_student.setModel( model ); 
catch(Exception e){
JOptionPane.showMessageDialog(null, e);

i changed the query to "select stu_id as 'id no',stu_name as 'name',Blood_group as 'blood group' from student" and "select stu_id as "\id no"\,stu_name as "\name"\,Blood_group as "\blood group"\ from student". But it didn't work.The column name remain the same.What should i do?

Lines 14-16 create the Vector of column names from the result set (did you write that code yourself, or just copy it?). If you want some other name(s), put them into the Vector instead of the current value(s).

Sorry i didn't understand.Shouldn't i change the query?Please make myself clear.I am biginner

If you understand that then you will already know that whatever names you want for the columns just put those names in Vector columnNames
It's as easy as that.

columnNames.addElement("Column 1");
columnNames.addElement("My name for col2");
columnNames.addElement("This is col 3");
mmake crystal clear
This question has already been answered. Start a new discussion instead.