J'ai regardé par tout et je ne trouve une solution.
Je veux montrer dans une table le résultat d'une requête SQL.
La requête rend son résultat mais je ne sais pas le mettre dans la table et la montrer.
Le problème est au final du code.
Merci beaucoup
Code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
 
package Entreprise;
 
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
 
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
 
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
 
public class ChercherCommandeFacture implements ActionListener{
   DefaultTableModel modelo;
   private JPanel jPanelSuperieur = null;
   private JLabel jLabeladresse = null;
   private JLabel jLabelVille = null;
   private JLabel jLabelCP = null;
   private JLabel jLabelNom = null;
   private JLabel jLabelCodeClient = null;
   private JLabel jLabelCl = null;
   private JLabel jLabelN = null;
   private JLabel jLabelA = null;
   private JLabel jLabelV = null;
   private JLabel jLabelP = null;
   private JLabel jLabelTel = null;
   private JLabel jLabelT = null;
   private JLabel jLabelTy = null;
   private JLabel jLabelType = null;
   private JButton jButtonNouvelleCommande = null;
   private JPanel jPanelCentral = null;
   private JTable jTableCenTab = null;
   private JFrame jFramePrincipal = null;  //  @jve:decl-index=0:visual-constraint="10,6"
   private JPanel jContentPaneConteneur = null;
   private JTabbedPane jTabbedPaneInferieur = null;
   private JTable jTableCommande = null;
   private JTable jTableFacture = null;
   private JLabel jLabelTitreRecherche = null;
   private JTextField jTextFieldCodeClient = null;
   private JTextField jTextFieldNom = null;
   private JTextField jTextFieldAdresse = null;
   private JTextField jTextFieldVille = null;
   private JTextField jTextFieldCodePostal = null;
   private JTextField jTextFieldTelephone = null;
   private JTextField jTextFieldTypeClient = null;
   private JButton jButtonChercherClient = null;
 
   /**
    * This method initializes jPanelSuperieur   
    *    
    * @return javax.swing.JPanel   
    */
   private JPanel getJPanelSuperieur() {
      if (jPanelSuperieur == null) {
         jLabelTitreRecherche = new JLabel("Recherche Client");
         jLabelTitreRecherche.setBounds(new Rectangle(12, 208, 145, 16));
         jLabelType = new JLabel("Type Client");
         jLabelType.setBounds(new Rectangle(15, 160, 69, 22));
         jLabelTy = new JLabel("");
         jLabelTy.setBounds(new Rectangle(92, 159, 137, 22));
         jLabelT = new JLabel("");
         jLabelT.setBounds(new Rectangle(92, 135, 137, 22));
         jLabelP = new JLabel("");
         jLabelP.setBounds(new Rectangle(92, 112, 137, 22));
         jLabelV = new JLabel("");
         jLabelV.setBounds(new Rectangle(93, 87, 137, 22));
         jLabelA = new JLabel("");
         jLabelA.setBounds(new Rectangle(92, 63, 137, 22));
         jLabelN = new JLabel("");
         jLabelN.setBounds(new Rectangle(93, 39, 137, 22));
         jLabelCl = new JLabel("");
         jLabelCl.setBounds(new Rectangle(94, 16, 137, 22));
         jLabelCodeClient = new JLabel("Code Client");
         jLabelCodeClient.setBounds(new Rectangle(18, 16, 70, 22));
         jLabelNom = new JLabel("Nom");
         jLabelNom.setBounds(new Rectangle(53, 39, 35, 22));
         jLabelCP = new JLabel("Code Postal");
         jLabelCP.setBounds(new Rectangle(11, 111, 75, 22));
         jLabelVille = new JLabel("Ville");
         jLabelVille.setBounds(new Rectangle(57, 87, 29, 22));
         jLabeladresse = new JLabel("Adresse");
         jLabeladresse.setBounds(new Rectangle(32, 63, 56, 22));
         jLabelTel = new JLabel("Téléphone");
         jLabelTel.setBounds(new Rectangle(16, 134, 68, 22));
         jPanelSuperieur = new JPanel();
         jPanelSuperieur.setLayout(null);
         jPanelSuperieur.add(jLabeladresse, null);
         jPanelSuperieur.add(jLabelVille, null);
         jPanelSuperieur.add(jLabelCP, null);
         jPanelSuperieur.add(jLabelNom, null);
         jPanelSuperieur.add(jLabelCodeClient, null);
         jPanelSuperieur.add(jLabelCl, null);
         jPanelSuperieur.add(jLabelN, null);
         jPanelSuperieur.add(jLabelA, null);
         jPanelSuperieur.add(jLabelV, null);
         jPanelSuperieur.add(jLabelP, null);
         jPanelSuperieur.add(jLabelTel, null);
         jPanelSuperieur.add(jLabelT, null);
         jPanelSuperieur.add(jLabelTy, null);
         jPanelSuperieur.add(jLabelType, null);
         jPanelSuperieur.add(getJButtonNouvelleCommande(), null);
         jPanelSuperieur.add(jLabelTitreRecherche, null);
         jPanelSuperieur.add(getJTextFieldCodeClient(), null);
         jPanelSuperieur.add(getJTextFieldNom(), null);
         jPanelSuperieur.add(getJTextFieldAdresse(), null);
         jPanelSuperieur.add(getJTextFieldVille(), null);
         jPanelSuperieur.add(getJTextFieldCodePostal(), null);
         jPanelSuperieur.add(getJTextFieldTelephone(), null);
         jPanelSuperieur.add(getJTextFieldTypeClient(), null);
         jPanelSuperieur.add(getJButtonChercherClient(), null);
      }
      return jPanelSuperieur;
   }
 
   /**
    * This method initializes jButtonNouvelleCommande   
    *    
    * @return javax.swing.JButton   
    */
   private JButton getJButtonNouvelleCommande() {
      if (jButtonNouvelleCommande == null) {
         jButtonNouvelleCommande = new JButton("Nouvelle Commande");
         jButtonNouvelleCommande.setBounds(new Rectangle(411, 68, 154, 84));
         jButtonNouvelleCommande.addActionListener(this);
      }
      return jButtonNouvelleCommande;
   }
 
 
 
   /**
    * This method initializes jTableCommande   
    *    
    * @return javax.swing.JTable   
    */
   private JTable getJTableCommande() {
      if (jTableCommande == null) {
         jTableCommande = new JTable();
      }
      return jTableCommande;
   }
 
   /**
    * This method initializes jTableFacture   
    *    
    * @return javax.swing.JTable   
    */
   private JTable getJTableFacture() {
      if (jTableFacture == null) {
         jTableFacture = new JTable();
      }
      return jTableFacture;
   }
   /**
    * This method initializes jTextFieldCodeClient   
    *    
    * @return javax.swing.JTextField   
    */
   private JTextField getJTextFieldCodeClient() {
      if (jTextFieldCodeClient == null) {
         jTextFieldCodeClient = new JTextField();
         jTextFieldCodeClient.setBounds(new Rectangle(240, 16, 158, 22));
      }
      return jTextFieldCodeClient;
   }
 
   /**
    * This method initializes jTextFieldNom   
    *    
    * @return javax.swing.JTextField   
    */
   private JTextField getJTextFieldNom() {
      if (jTextFieldNom == null) {
         jTextFieldNom = new JTextField();
         jTextFieldNom.setBounds(new Rectangle(240, 39, 158, 22));
      }
      return jTextFieldNom;
   }
 
   /**
    * This method initializes jTextFieldAdresse   
    *    
    * @return javax.swing.JTextField   
    */
   private JTextField getJTextFieldAdresse() {
      if (jTextFieldAdresse == null) {
         jTextFieldAdresse = new JTextField();
         jTextFieldAdresse.setBounds(new Rectangle(240, 63, 158, 22));
      }
      return jTextFieldAdresse;
   }
 
   /**
    * This method initializes jTextFieldVille   
    *    
    * @return javax.swing.JTextField   
    */
   private JTextField getJTextFieldVille() {
      if (jTextFieldVille == null) {
         jTextFieldVille = new JTextField();
         jTextFieldVille.setBounds(new Rectangle(240, 87, 158, 22));
      }
      return jTextFieldVille;
   }
 
   /**
    * This method initializes jTextFieldCodePostal   
    *    
    * @return javax.swing.JTextField   
    */
   private JTextField getJTextFieldCodePostal() {
      if (jTextFieldCodePostal == null) {
         jTextFieldCodePostal = new JTextField();
         jTextFieldCodePostal.setBounds(new Rectangle(240, 112, 158, 22));
      }
      return jTextFieldCodePostal;
   }
 
   /**
    * This method initializes jTextFieldTelephone   
    *    
    * @return javax.swing.JTextField   
    */
   private JTextField getJTextFieldTelephone() {
      if (jTextFieldTelephone == null) {
         jTextFieldTelephone = new JTextField();
         jTextFieldTelephone.setBounds(new Rectangle(240, 135, 158, 22));
      }
      return jTextFieldTelephone;
   }
 
   /**
    * This method initializes jTextFieldTypeClient   
    *    
    * @return javax.swing.JTextField   
    */
   private JTextField getJTextFieldTypeClient() {
      if (jTextFieldTypeClient == null) {
         jTextFieldTypeClient = new JTextField();
         jTextFieldTypeClient.setBounds(new Rectangle(240, 159, 158, 22));
      }
      return jTextFieldTypeClient;
   }
 
   /**
    * This method initializes jButtonChercherClient   
    *    
    * @return javax.swing.JButton   
    */
   private JButton getJButtonChercherClient() {
      if (jButtonChercherClient == null) {
         jButtonChercherClient = new JButton("Chercher Client");
         jButtonChercherClient.setBounds(new Rectangle(243, 192, 154, 24));
         jButtonChercherClient.addActionListener(this);
      }
      return jButtonChercherClient;
   }
 
   /**
    * This method initializes jTableCenTab   
    *    
    * @return javax.swing.JTable   
    */
   private JTable getJTableCenTab() {
      if (jTableCenTab == null) {
         //jTableCenTab = new JTable();
 
         modelo = new DefaultTableModel();
         jTableCenTab = new JTable(modelo);
      }
      return jTableCenTab;
   }
 
   /**
    * This method initializes jContentPaneConteneur   
    *    
    * @return javax.swing.JPanel   
    */
   private JPanel getJContentPaneConteneur() {
      if (jContentPaneConteneur == null) {
         GridLayout gridLayout = new GridLayout(3,1);
         jContentPaneConteneur = new JPanel();
         jContentPaneConteneur.setLayout(gridLayout);
         jContentPaneConteneur.add(getJPanelSuperieur(), null);
         jContentPaneConteneur.add(getJPanelCentral(), null);
         jContentPaneConteneur.add(getJTabbedPaneInferieur(), null);
      }
      return jContentPaneConteneur;
   }
 
   /**
    * This method initializes jTabbedPaneInferieur   
    *    
    * @return javax.swing.JTabbedPane   
    */
   private JTabbedPane getJTabbedPaneInferieur() {
      if (jTabbedPaneInferieur == null) {
         jTabbedPaneInferieur = new JTabbedPane();
         jTabbedPaneInferieur.addTab("Commande", null, getJTableCommande(), null);
         jTabbedPaneInferieur.addTab("Facture", null, getJTableFacture(), null);
      }
      return jTabbedPaneInferieur;
   }
 
   /**
    * This method initializes jPanelCentral   
    *    
    * @return javax.swing.JPanel   
    */
   private JPanel getJPanelCentral() {
      if (jPanelCentral == null) {
         GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
         gridBagConstraints1.fill = GridBagConstraints.BOTH;
         gridBagConstraints1.gridy = 0;
         gridBagConstraints1.weightx = 1.0;
         gridBagConstraints1.weighty = 1.0;
         gridBagConstraints1.gridx = 0;
         jPanelCentral = new JPanel();
         jPanelCentral.setLayout(new GridBagLayout());
         jPanelCentral.add(getJTableCenTab(), gridBagConstraints1);
      }
      return jPanelCentral;
   }
 
    public void visualiserFenetre() {
      jFramePrincipal = new JFrame("Recherche Commande - Facture");
      jFramePrincipal.setSize(new Dimension(602, 724));
      jFramePrincipal.setMinimumSize(new Dimension(602, 724));
      jFramePrincipal.setContentPane(getJContentPaneConteneur());
      jFramePrincipal.setVisible(true);
    }
 
 
    public void actionPerformed(ActionEvent e){
 
          if(e.getSource().equals(jButtonChercherClient)){            
            try {   
               BaseDeDatos bd = new BaseDeDatos();//Dans cette classe on garde la connexion y les requettes SQL
            bd.etablirConnexion();
            //prend les données des TextField pour faire la requette
            ResultSet resultat = bd.getSelectClients(jTextFieldCodeClient.getText(), jTextFieldNom.getText(), jTextFieldAdresse.getText(),
                  jTextFieldCodePostal.getText(), jTextFieldVille.getText(), jTextFieldTelephone.getText(), jTextFieldTypeClient.getText()  );
            if ( resultat.next() ){
               ResultSetMetaData metaDatas = resultat.getMetaData();
               int nombreColonnes = metaDatas.getColumnCount();
               Object[] etiquettes = new Object[nombreColonnes];
               for (int i = 0; i < nombreColonnes; i++) {
                  etiquettes = metaDatas.getColumnLabel(i + 1);
               }
               while (resultat.next()) {
 
                  Object [] fila = new Object[nombreColonnes];
                  for (int i=0;i<nombreColonnes;i++)
                     fila = resultat.getObject(i+1);
                  modelo.setColumnIdentifiers(etiquettes);
                  modelo.addRow(fila);
 
                  getJTableCenTab().addRow(fila);//la methode getJTableCenTab est la table que on veut passer à getJPanelCentral()
                                            //et ceci on le passe à getJContentPaneConteneur() et ceci à la JFramePrincipal
//ICI LE ERREUR: The method addRow(Object[]) is undefined for the type JTable
 
               }
 
            }else{
 
            }
 
 
            bd.fermeConnexion();
            } catch (Exception en) {en.printStackTrace();}
             }else{
                if(e.getSource().equals(jButtonNouvelleCommande)){
                CommandeFacture fact = new CommandeFacture();
                fact.visualiserFenetre();
               }         
       }
    }
 
 
 
   public static void main(String[] args) {
      ChercherCommandeFacture fact = new ChercherCommandeFacture();
      fact.visualiserFenetre();
   }
 
}