Q: add column to jtable dynamically on netbeans my code is this :
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    DefaultTableModel model=(DefaultTableModel)pl.getModel();               
        String urlBaseDonnes="jdbc:mysql://localhost:3306/test";
        Connection con;
        try{
        Class.forName("com.mysql.jdbc.Driver");
        }catch(ClassNotFoundException ex){
            System.out.println(ex);
        }
        try{
            con =DriverManager.getConnection(urlBaseDonnes,"root","");
        try (Statement stmt = con.createStatement()) {
            ResultSet rs = stmt.executeQuery("SELECT * FROM news");
            ResultSetMetaData rsMetaData = rs.getMetaData();
            int numberOfColumns = rsMetaData.getColumnCount();
            System.out.println("resultSet MetaData column Count=" + numberOfColumns);
            int j=0;
            pl.setModel(new javax.swing.table.DefaultTableModel(new Object [][] {},new String [] {"ddd","fgg","nl"}));

            // get the name of the column, and changing it

            for (int i = 1 ; i <= numberOfColumns; i++) {
                ChangeName(pl,j,rsMetaData.getColumnName(i));
                System.out.println(rsMetaData.getColumnName(i));
                System.out.println(j);
                j= j+1;
            }
            String query="SELECT * FROM news";
            rs=stmt.executeQuery(query);

            //Show the database

            while(rs.next()){
                String id=rs.getString("id");
                String titre=rs.getString("titre");
                String contenu=rs.getString("contenu");  
                model.addRow(new Object[]{id,titre,contenu});
            }
            rs.close();
        }
        con.close();
        System.out.println("close the database");
        }catch(SQLException ex){
            System.out.println(ex);
        }
}       

My goal is to change the name of the columns dynamically when i change the name of my table, this code can change the name of the column but when it's come to showing the content of the database it doesn't work, also i can't add column, for exemple if i choose a table that have 4 column, i'll have an error. I tried to add column using a DefaultTableModel but it didn't work.
could you please help me with the part of adding column dynamically ? and tell me why this code doesn't show what's on the database ?
Thanks

A: 
that the data that are in my database are not shown. this code only changes the name of the column.

First you access the TableModel of the table:
DefaultTableModel model=(DefaultTableModel)pl.getModel(); 

Then you change the TableModel of the table:
pl.setModel(new javax.swing.table.DefaultTableModel(new Object [][] {},new String [] {"ddd","fgg","nl"}));

Then you add the data from the database to the "old" model:
model.addRow(new Object[]{id,titre,contenu});

So the data is NOT added to the current model.
If you want to create a new model then your code should be something like:
DefaultTableModel model = DefaultTableModel(Object[] columnNames, int rowCount);
pl.setModel( model ); 

Then your code will add the database data to the real model.
The question is why are you trying to hardcode the column name? When you do a select * from the database you don't know how many columns of data will be returned. You should be using more generic code. See the TableFromDatabaseExample.java code from Table From Database.
