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(){
try{
String sql="select stu_id ,stu_name ,Blood_group from student";
pst=conn.prepareStatement(sql);
rs=pst.executeQuery();
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++) {
columnNames.addElement(md.getColumnName(i));
}
while (rs.next()) {
for (int i = 1; i <= columnCount; i++) {
row.addElement(rs.getObject(i));
}
data.addElement(row);
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?