0

Am programming of the application that manage football's players and clubs I'm real stopped in small part and I couldn't find for it any solution after the try of many ideas.

Simply: I have a JTable and I want to refresh it after any task (Insert, Update or Delete).

That's the code

    //for fill the JTable
    // class controllApp

        class controllApp(){

        public DefaultTableModel getCleubData() {
                Vector<Vector<String>> data = new Vector<Vector<String>>();
                Vector<String> colum = new Vector<String>();
                colum.add("id_c");
                colum.add("coach");
                colum.add("nom_cleub");
                colum.add("DATE_CREATION");
                colum.add("COULEUR_MAILLOT");
                colum.add("COUNTRY");

                String query = "select id_c,coach,nom_cleub,date_creation,couleur_maillot,country from CLEUB ORDER BY ID_C";

                try {
                    Connection conn = ReportDriver.connectDB(DB_CONNECTION, DB_USER,
                            DB_PASSWORD);
                    stmt = conn.createStatement();
                    ResultSet rs = stmt.executeQuery(query);
                    while (rs.next()) {

                        Vector<String> vstring = new Vector<String>();

                        vstring.add(rs.getString("id_c"));
                        vstring.add(rs.getString("coach"));
                        vstring.add(rs.getString("nom_cleub"));
                        java.sql.Date date = rs.getDate("date_creation");
                        java.text.DateFormat df = java.text.DateFormat.getDateInstance();
                        vstring.add(df.format(date));
                        vstring.add(rs.getString("couleur_maillot"));
                        vstring.add(rs.getString("country"));
                        vstring.add("\n\n\n\n\n\n\n");

                        data.add(vstring);
                    }
                } catch (SQLException e) {
                    e.printStackTrace();
                } finally {
                    if (stmt != null) {
                        try {
                            stmt.close();
                        } catch (SQLException ex) {

                        }
                    }
                }
                DefaultTableModel d = new DefaultTableModel(data, colum);
                return d;
            }

        }




        //fill frame in other class (frame classe)
        // class frame() to call controllAPP.getJoueurdata()    



        class frame(){

        private static JTable table1;
        AbstractTableModel model;
                model = new controllApp().getJoueurData();
                table1 = new JTable(model);
                JScrollPane scrollPane = new JScrollPane(table1);
                scrollPane.setBounds(6, 29, 807, 297);
                panel.add(scrollPane);
    }
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
mugiwaradz
  • 393
  • 1
  • 3
  • 15
  • For better help sooner, post an [MCVE](http://www.stackoverflow/mcve) (Minimal, Complete, Verifiable Example). Hard code some data to factor out the DB. – Andrew Thompson Jul 16 '14 at 08:17
  • 2
    `scrollPane.setBounds(..)` 1) Swing GUIs might have to work on different platforms, using different PLAFs, on different screen sizes and resolutions with different default settings for font size. As such, they are not conducive to exact placement of components. Instead use layout managers, or [combinations of layout managers](http://stackoverflow.com/a/5630271/418556) as well as [layout padding and borders](http://stackoverflow.com/q/17874717/418556) for white space. 2) Use a logical & consistent code formatting style! The code indentation is intended to help people follow the program flow. – Andrew Thompson Jul 16 '14 at 08:18
  • 3
    Oh, but for a table, we would typically update the **table model** and the rest is automatic. – Andrew Thompson Jul 16 '14 at 08:20
  • 1
    What part of (insert, update, delete) requirement are you having problems with? Is it the jdbc part? Is it the GUI part? Is it both? Have you made any attempts? – Paul Samsotha Jul 16 '14 at 09:50
  • probleme is in the gui part – mugiwaradz Jul 16 '14 at 11:41

1 Answers1

0

the solution is to get the Jtable's Model then add Vector data to it, then you have to set the model to the existing JTable.

The Appsolit
  • 89
  • 10