bonjour à tous j'essaie de faire une application client-serveur pour enregistrer des informations dans une bd postgresql j'ai suivit le tutoriel de developpez.com et lorsque j’exécute mes codes j'ai des exceptions que je ne comprends pqs voila mes codes:
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
package monpackage;
 
import javax.swing.SwingUtilities;
import java.awt.Color;
import java.awt.Cursor;
 
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.Rectangle;
import javax.swing.JTextField;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RMISecurityManager;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.net.*;
 
import javax.swing.JComboBox;
import javax.swing.JButton;
 
public class LancerClient extends JFrame {
 
	private static final long serialVersionUID = 1L;
	private JPanel jContentPane = null;
	private JPanel jPanel = null;
	private JLabel jLabel = null;
	private JLabel jLabel1 = null;
	private JLabel jLabel2 = null;
	private JLabel jLabel3 = null;
	private JLabel jLabel4 = null;
	private JTextField jTextField = null;
	private JTextField jTextField1 = null;
	private JTextField jTextField2 = null;
	private JComboBox jComboBox = null;
	private JComboBox jComboBox1 = null;
	private JButton jButton = null;
	private JLabel jLabel5 = null;
	public Etudiant et;
	private JButton jButton1 = null;
	private JButton jButton2 = null;
	/**
         * This method initializes jPanel       
         *      
         * @return javax.swing.JPanel   
         */
	private JPanel getJPanel() {
		if (jPanel == null) {
			jLabel4 = new JLabel();
			jLabel4.setBounds(new Rectangle(10, 180, 100, 30));
			jLabel4.setText("Niveau");
			jLabel3 = new JLabel();
			jLabel3.setBounds(new Rectangle(10, 140, 100, 30));
			jLabel3.setText("Filière");
			jLabel2 = new JLabel();
			jLabel2.setBounds(new Rectangle(10, 100, 100, 30));
			jLabel2.setText("Matricule:");
			jLabel1 = new JLabel();
			jLabel1.setBounds(new Rectangle(10, 60, 50, 30));
			jLabel1.setText("Prenom:");
			jLabel = new JLabel();
			jLabel.setBounds(new Rectangle(10, 20, 50, 30));
			jLabel.setText("Nom:");
			jPanel = new JPanel();
			jPanel.setBorder(BorderFactory.createTitledBorder("Formulaire d'enregistrement"));
			jPanel.setLayout(null);
			jPanel.setBounds(new Rectangle(12, 45, 531, 214));
			jPanel.add(jLabel, null);
			jPanel.add(jLabel1, null);
			jPanel.add(jLabel2, null);
			jPanel.add(jLabel3, null);
			jPanel.add(jLabel4, null);
			jPanel.add(getJTextField(), null);
			jPanel.add(getJTextField1(), null);
			jPanel.add(getJTextField2(), null);
			jPanel.add(getJComboBox(), null);
			jPanel.add(getJComboBox1(), null);
			jPanel.setBackground(Color.red);
		}
		return jPanel;
	}
 
	/**
         * This method initializes jTextField   
         *      
         * @return javax.swing.JTextField       
         */
	private JTextField getJTextField() {
		if (jTextField == null) {
			jTextField = new JTextField();
			jTextField.setBounds(new Rectangle(120, 20, 200, 30));
		}
		return jTextField;
	}
 
	/**
         * This method initializes jTextField1  
         *      
         * @return javax.swing.JTextField       
         */
	private JTextField getJTextField1() {
		if (jTextField1 == null) {
			jTextField1 = new JTextField();
			jTextField1.setBounds(new Rectangle(120, 60, 200, 30));
		}
		return jTextField1;
	}
 
	/**
         * This method initializes jTextField2  
         *      
         * @return javax.swing.JTextField       
         */
	private JTextField getJTextField2() {
		if (jTextField2 == null) {
			jTextField2 = new JTextField();
			jTextField2.setBounds(new Rectangle(120, 100, 200, 30));
		}
		return jTextField2;
	}
 
	/**
         * This method initializes jComboBox    
         *      
         * @return javax.swing.JComboBox        
         */
	private JComboBox getJComboBox() {
		if (jComboBox == null) {
			jComboBox = new JComboBox();
			jComboBox.setBounds(new Rectangle(120, 140, 100, 30));
			jComboBox.addItem("");
			jComboBox.addItem("GTR");
			jComboBox.addItem("GE");
			jComboBox.addItem("MIP");
			jComboBox.addItem("IG");
			jComboBox.addItem("GC");
		}
		return jComboBox;
	}
 
	/**
         * This method initializes jComboBox1   
         *      
         * @return javax.swing.JComboBox        
         */
	private JComboBox getJComboBox1() {
		if (jComboBox1 == null) {
			jComboBox1 = new JComboBox();
			jComboBox1.setBounds(new Rectangle(120, 180, 100, 30));
			jComboBox1.addItem("");
			jComboBox1.addItem("1");
			jComboBox1.addItem("2");
			jComboBox1.addItem("3");
		}
		return jComboBox1;
	}
 
	/**
         * This method initializes jButton      
         *      
         * @return javax.swing.JButton  
         */
	private JButton getJButton() {
		if (jButton == null) {
			jButton = new JButton();
			jButton.setBounds(new Rectangle(40, 265, 129, 28));
			jButton.setText("Enregistrer");
			jButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
			jButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					String req="insert into etudiant(nom,prenom,matricule,filiere,niveau) values('"+jTextField.getText()+"','"+jTextField1.getText()+"','"+jTextField2.getText()+"','"+jComboBox.getSelectedItem()+"','"+jComboBox1.getSelectedItem()+"')";
					try {
						et.SQLupdate(req);
						jTextField.setText("");
						jTextField1.setText("");
						jTextField2.setText("");
						jComboBox.setSelectedIndex(0);
						jComboBox1.setSelectedIndex(0);
					} catch (RemoteException e1) {
						e1.printStackTrace();
					}
				}
			});
		}
		return jButton;
	}
 
	/**
         * This method initializes jButton1     
         *      
         * @return javax.swing.JButton  
         */
	private JButton getJButton1() {
		if (jButton1 == null) {
			jButton1 = new JButton();
			jButton1.setBounds(new Rectangle(193, 264, 122, 30));
			jButton1.setText("Annuler");
			jButton1.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					jTextField.setText("");
					jTextField1.setText("");
					jTextField2.setText("");
					jComboBox.setSelectedIndex(0);
					jComboBox1.setSelectedIndex(0);
				}
			});
		}
		return jButton1;
	}
 
	/**
         * This method initializes jButton2     
         *      
         * @return javax.swing.JButton  
         */
	private JButton getJButton2() {
		if (jButton2 == null) {
			jButton2 = new JButton();
			jButton2.setBounds(new Rectangle(339, 265, 121, 30));
			jButton2.setText("Lister");
			jButton2.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					new ListeEtudiant().setVisible(true);
				}
			});
		}
		return jButton2;
	}
 
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				LancerClient thisClass = new LancerClient();
				thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				thisClass.setVisible(true);
			}
		});
	}
 
	public LancerClient() {
		super();
		initialize();
		System.out.println("Lancement du client...");
		if(System.getSecurityManager()==null){
			System.setSecurityManager(new RMISecurityManager());
		}
		try{
			Remote r=Naming.lookup("rmi://127.0.0.1:10990/TestRMI");
			System.out.println(r);
			if(r instanceof Etudiant){
				et=(Etudiant)r;
				System.out.println("Création de l'objet");
			}
		}catch(RemoteException e){
			e.printStackTrace();
		}
		catch(MalformedURLException e){
			e.printStackTrace();
		}
		catch(NotBoundException e){
			e.printStackTrace();
		}
		System.out.println("Fin du client");
	}
 
	private void initialize() {
		this.setSize(574, 345);
		this.setContentPane(getJContentPane());
		this.setTitle("JFrame");
	}
 
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jLabel5 = new JLabel();
			jLabel5.setBounds(new Rectangle(142, 6, 270, 37));
			jLabel5.setText("Formulaire d'enregistrement de l'etudiant");
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(getJPanel(), null);
			jContentPane.add(getJButton(), null);
			jContentPane.add(jLabel5, null);
			jContentPane.add(getJButton1(), null);
			jContentPane.add(getJButton2(), null);
			jContentPane.setBackground(Color.blue);
		}
		return jContentPane;
	}
 
}  //  @jve:decl-index=0:visual-constraint="10,10"
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
package monpackage;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.beans.Statement;
import java.sql.*;
import java.util.Enumeration;
import java.util.Properties;
import javax.swing.JOptionPane;
public class EtudiantImpl extends UnicastRemoteObject implements Etudiant{
	private static final long serialVersionUID = 1L;
	  static Connection con = null;
	  static ResultSet resultats = null;
	  private Message msg = new Message();
	protected EtudiantImpl() throws RemoteException {
		super();
		try {
			Class.forName("org.postgresql.Driver");
			String url = "jdbc:postgresql://127.0.0.1:5432/Universite";
			String user = "postgres";
			String passwd = "keryjames";
			con = DriverManager.getConnection(url, user, passwd);
			//JOptionPane.showMessageDialog(null, "Ok");
		} catch (Exception e) {
			e.printStackTrace();
			System.out.print(e);
		}	
	}
	//@Override
	public void SQLupdate(String req) throws RemoteException {
	     try {
 
		       java.sql.Statement stmt =  con.createStatement();
		       ((java.sql.Statement) stmt).executeUpdate(req);
		       msg.dialog("requette executée avec succes");
		     }
		     catch (SQLException e) {
		       msg.error("Impossible d'executer la requete : \n" + e);
		     }
		   }
 
		  public void SQLupdateNotResponse(String req) {
			    try {
 
				      Statement stmt = (Statement) con.createStatement();
				      ((java.sql.Statement) stmt).executeUpdate(req);
				      msg.dialog("requette executée avec succes");
				    }
				    catch (SQLException e) {
				      msg.error("Impossible d'executer la requete: \n" + e.getMessage());
				    }
	}
//	@Override
	public String[][] DataQuery(String req) throws RemoteException {
	     int rows = numRows(req);
	     int cols = numCols(req);
	     String[][] donnees = new String[rows][cols];
 
	     SQLquery(req);
	     try {
	       ResultSetMetaData rsmd = resultats.getMetaData();
	       int nbCols = rsmd.getColumnCount();
	       boolean encore = resultats.next();
	       int numTuple = 0;
	       while (encore) {
	         for (int i = 0; i < nbCols; i++) {
	           donnees[numTuple][i] = resultats.getString(i + 1);
	         }
	         encore = resultats.next();
	         numTuple++;
	       }
	       resultats.close();
 
	     }
	     catch (SQLException e) {
	      // msg.error(e.getMessage());
	     }
	     return donnees;
	}
	   public int numCols(String sql)
 
	   {
	     int nbre = 0;
	     SQLquery(sql);
	     try {
	       ResultSetMetaData rsmd = resultats.getMetaData();
	       nbre = rsmd.getColumnCount();
	       resultats.close();
	     }
	     catch (SQLException e) {
	      // msg.error(e.getMessage());
	     }
	     return nbre;
	   }
	   public int numRows(String sql) {
		     int nbre = 0;
		     SQLquery(sql);
		     try {
		       //ResultSetMetaData rsmd = resultats.getMetaData();
		       //int nbCols = rsmd.getColumnCount();
		       boolean encore = resultats.next();
		       while (encore) {
		         encore = resultats.next();
		         nbre++;
		       }
		       resultats.close();
		     }
		     catch (SQLException e) {
		       //msg.error(e.getMessage());
		     }
		     return nbre;
		   }
		  public void SQLquery(String sql) {
			    //execution de la requête
 
			    try {
			      Statement stmt = (Statement) con.createStatement();
			      resultats = ((java.sql.Statement) stmt).executeQuery(sql);
			    }
			    catch (SQLException e) {
			     // msg.error("Impossible d'exécuter la requête" + e.getMessage());
			      //System.exit(0);
			    }
 
			  }
		   public boolean SQLupdateResponse(String req) {
			     try {
 
			       Statement stmt = (Statement) con.createStatement();
			       ((java.sql.Statement) stmt).executeUpdate(req);
			       msg.dialog("requette executée avec succes");
			       return true;
			     }
			     catch (SQLException e) {
			       msg.error("Impossible d'executer la requete: \n" + e.getMessage());
			       return false;
			     }
 
			   }
 
}
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
package monpackage;
import java.net.Inet4Address;
import java.net.MalformedURLException;
import java.net.UnknownHostException;
import java.rmi.Naming;
import java.rmi.RMISecurityManager;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
 
 
public class LancerServeur {
 
	public static  void main (String[] args) throws UnknownHostException
	{
 
		try{
 
		LocateRegistry.createRegistry(10990);
		System.out.println("Mise en place de la sécurité Manger");
		if(System.getSecurityManager()==null)
		{
			System.setSecurityManager(new RMISecurityManager());
		}
		EtudiantImpl et = new EtudiantImpl();
		String url="rmi://127.0.0.1/TestRMI";
		//String url="rmi://127.0.0.1/TestRMI";
		System.out.println("enregistrement de l'objet avec l'url "+url);
		Naming.rebind(url, et);
		System.out.println("Serveur lancé");
		}catch(RemoteException e)
		{
		   e.printStackTrace();
 
		}
		catch(MalformedURLException e)
		{  
			e.printStackTrace();
		}
	}
 
 
}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
package monpackage;
 
import java.rmi.Remote;
import java.rmi.RemoteException;
 
public interface Etudiant extends Remote{
	public void SQLupdate(String req) throws RemoteException;
	public String[][] DataQuery(String req) throws RemoteException; 
 
}
lorsque j'execute les serveur pas de problème mais c'est au niveau du client que l'objet distant n'est pas créé