bonjour j'ai du mal à me connecter à ma base de données via cet applet, prière de me suggerer des aides de votre part.
svp prière de considerer ma contrainte du temps
merci beaucoup
voilà mon 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
 
import java.sql.*;
import java.awt.Button;
import java.awt.Choice;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
 
import javax.swing.ButtonGroup;
import javax.swing.JApplet;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JRadioButton;
import javax.swing.JSpinner.DateEditor;
import javax.swing.JTextField;
 
public class GestientDeProduit extends JApplet {
 
       // Les objets globauxs
 
	  JTextField txCode,txDesignation, txReference, txNUDeSerier, txTotale, txDateReception, txRestant, txCosomme, txDateExpiration, txType; 
	  Choice chType, chLaboratoir, chMedecin;
	 String strCode,strDesignation, strReference, strNUDeSerier, strTotale, strDateReception, strRestant, strCosomme, strDateExpiration, strType; 
	  String strTypechoix, strLaboratoir, strMedecin;
	  //  recuperation des variables globales
 
 
	  public void init(){
	    // disposition d'éléments
	    setLayout(null);
 
		    // Différentes fontes à utiliser
 
	    Font fonte1= new Font("TimesRoman", Font.PLAIN, 14);
	    Font fonte2= new Font("TimesRoman", Font.BOLD, 20);
	    Font fonte3= new Font("TimesRoman", Font.ITALIC + Font.BOLD, 14);
 
	    // En-tête :
 
		JLabel lbMINIST = new JLabel(" GESTION DE PRODUIT DE STOCK ");
		lbMINIST.setBounds(100,20,900,25);
		add(lbMINIST); lbMINIST.setFont(fonte2);
 
		JLabel lblIdentite = new JLabel("I. IDENTIFICATION DE PRODUIT ");
	    add(lblIdentite); lblIdentite.setBounds(10, 100, 300, 23);
		lblIdentite.setFont(new Font("Dialog", 1, 16));
 
	    // JLabels et JTextfields
		JLabel lbCode=new JLabel("1. Numero d'ordre du produit :"); lbCode.setBounds(30,130,190,22);
		lbCode.setFont(fonte3); add(lbCode);
		txCode=new JTextField(); txCode.setBounds(230,130,80,22); txCode.setFont(fonte1);txCode.disable();
		add(txCode); 
	    JLabel lbDesignation = new JLabel("3. Designation :"); lbDesignation.setBounds(30, 160, 100, 22);
	    add(lbDesignation); lbDesignation.setFont(fonte3);
		txDesignation = new JTextField(); txDesignation.setBounds(130, 160, 130, 22);
	    add(txDesignation); txDesignation.setFont(fonte1);
 
	    JLabel lbReference = new JLabel("3. Référence :"); lbReference.setBounds(30, 190, 100, 22);
	    add(lbReference); lbReference.setFont(fonte3);
	    txReference = new JTextField(); txReference.setBounds(140, 190, 160, 22);
	    add(txReference); txReference.setFont(fonte1);
 
		JLabel lbNUDeSerier = new JLabel("4. Numero de serier:"); lbNUDeSerier.setBounds(30, 220, 130, 22);
	    add(lbNUDeSerier); lbNUDeSerier.setFont(fonte3);
		txNUDeSerier = new JTextField(); txNUDeSerier.setBounds(170, 220, 160, 22);
	    add(txNUDeSerier); txNUDeSerier.setFont(fonte1);
 
		JLabel lbTypePro = new JLabel("6. Type de produit :"); lbTypePro.setBounds(30, 250, 130, 22);
	    add(lbTypePro); lbTypePro.setFont(fonte3);
		chType = new Choice(); chType.setBounds(160, 250, 140, 22);
	    add(chType); chType.setFont(fonte1);
	    chType.addItem("Choisir dans la liste"); chType.addItem("Consomable"); chType.addItem("Non Consomable");
 
	    JLabel lbLaboratoirDilévrant = new JLabel("6. Laboratoire dilévrant :"); lbLaboratoirDilévrant.setBounds(30, 280, 140, 22);
	    add(lbLaboratoirDilévrant); lbLaboratoirDilévrant.setFont(fonte3);
	    chLaboratoir = new Choice(); chLaboratoir.setBounds(180, 280, 120, 22);
	    add(chLaboratoir); chLaboratoir.setFont(fonte1);
	    chLaboratoir.addItem("Choisi dans la liste"); chLaboratoir.addItem("Lbo1"); chLaboratoir.addItem("Labo2");
 
		JLabel lbGestion = new JLabel("I. GESTION DE STOCK DE PRODUIT :");
	    add(lbGestion); lbGestion.setBounds(10, 330, 400, 23);
	    lbGestion.setFont(new Font("Dialog", 1, 16));
 
 
	    JLabel lbTotale = new JLabel("6. Nombre totale :"); lbTotale.setBounds(30,360, 130, 22);
	    add(lbTotale); lbTotale.setFont(fonte3);
		txTotale = new JTextField(); txTotale.setBounds(170, 360, 100, 22);
	    add(txTotale); txTotale.setFont(fonte1);
 
		JLabel lbCosomme = new JLabel("7. Nombre consommé :"); lbCosomme.setBounds(30, 390, 144, 22);
	    add(lbCosomme); lbCosomme.setFont(fonte3);
		txCosomme = new JTextField(); txCosomme.setBounds(180, 390, 160, 22);
	    add(txCosomme); txCosomme.setFont(fonte1);
 
		JLabel lbRestant = new JLabel("8. Nombre restant:"); lbRestant.setBounds(30,420 , 130, 22);
	    add(lbRestant); lbRestant.setFont(fonte3);
		txRestant = new JTextField(); txRestant.setBounds(160, 420, 140, 22);
	    add(txRestant); txRestant.setFont(fonte1);
 
		JLabel lbDateReception = new JLabel("9. Date de réception :"); lbDateReception.setBounds(30, 450, 130, 22);
	    add(lbDateReception); lbDateReception.setFont(fonte3);
		txDateReception = new JTextField(); txDateReception.setBounds(160, 450, 160, 22);
	    add(txDateReception); txDateReception.setFont(fonte1);
 
	    JLabel lbDateExpiration = new JLabel("10. Date d'expiration :"); lbDateExpiration.setBounds(30, 480, 130, 22);
	    add(lbDateExpiration); lbDateExpiration.setFont(fonte3);
		txDateExpiration = new JTextField(); txDateExpiration.setBounds(180, 480, 160, 22);
	    add(txDateExpiration); txDateExpiration.setFont(fonte1);
 
	    Button btRechercher = new Button(" Rechercher ");  btRechercher.setBounds(10,530,100,27); 
	    add(btRechercher); btRechercher.setFont(fonte1);
 
	    Button btAjouter = new Button(" Ajouter "); btAjouter.setBounds(130,530,100,27); 
	    add(btAjouter); btAjouter.setFont(fonte1);
 
 
	    Button btModifier = new Button(" Modifier ");   btModifier.setBounds(250,530,100,27);
	    add(btModifier); btModifier.setFont(fonte1);
 
	    Button btEffacer = new Button(" Effacer ");   btEffacer.setBounds(370,530,100,27);
	    add(btEffacer); btEffacer.setFont(fonte1);
 
	    Button btQuitter = new Button(" Quitter ");   btQuitter.setBounds(130,570,100,27);
	    add(btQuitter); btQuitter.setFont(fonte1);
 
	    	//cliquer sur le bouton Quitter
	    btQuitter.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent exit){
				System.exit(0);
			}
		});
 
	  //cliquer sur le bouton effacer.
	  	btEffacer.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent effacer) {
				// TODO Auto-generated method stub
				txDesignation.setText(" ");			txCosomme.setText("");
				txReference.setText("");			txRestant.setText("");
				txNUDeSerier.setText("");			txTotale.setText("");	txDateExpiration.setText("");
				txDateReception.setText("");		txType.setText("");
				chLaboratoir.addItem(null);	chMedecin.addItem(null);	chType.addItem(null);
				}
		});
 
	  //cliquer sur le bouton Ajouter
	  		btAjouter.addActionListener(new ActionListener() {
	  			public void actionPerformed(ActionEvent add) {
					// TODO Auto-generated method stub
					ajouter(add);
				}
			});
 
	  	//cliquer sur le bouton Modifier
	  		btModifier.addActionListener(new ActionListener() {
	  			public void actionPerformed(ActionEvent mo) {
					// TODO Auto-generated method stub
					modifier(mo);
				}
			});
 
	  	//cliquer sur le bouton Rechercher
	  		btRechercher.addActionListener(new ActionListener() {
	  			public void actionPerformed(ActionEvent Sh) {
					// TODO Auto-generated method stub
					rechercher(Sh);
				}
			});
} // fin de methode init();
 
	  		// Traitement des methodes dans les variable globales;
 
 
//************************    bouton ajouter    ***************************
	  public void ajouter(ActionEvent add){
		  //construction de requetes;
		  String strDesignation=txDesignation.getText(), strReference=txReference.getText(),strNUDeSerier=txNUDeSerier.getText(), strTotale=txTotale.getText(), strDateReception=txDateReception.getText();
		   String strRestant=txRestant.getText(), strCosomme=txCosomme.getText(), strDateExpiration=txDateExpiration.getText();
		  String strType=txType.getText(), strTypeChoix=chType.getSelectedItem(), strLaboratoir=chLaboratoir.getSelectedItem();
		 String  strMedecin=chMedecin.getSelectedItem(),strCode=txCode.getText();
		  String
		  requete1= "INSERT INTO mabase.produit (id_pro, designation_pro, reference_pro, numero_pro, " +
		  		"type_pro, labo_pro, totale_pro, consommer_pro, restant_pro, dateReception_pro, " +
		  		"dateExpiration) VALUES ('1','"+strDesignation+"', '"+strReference+"','"+strNUDeSerier+"'," +
		  				"'" +strTotale+"','"+ strDateReception+"','"+ strRestant+"', '"+strCosomme+"','" +strDateExpiration+"'," +
		  						"'"+strType+"','" +strTypeChoix+"','" +strLaboratoir+"','"+strMedecin+"'";
 
		// connexion au serveur.
		  Connection conn = null;
		  ResultSet Resultats;
 
 
		 //chargement de pilote
		 try{	
			 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		 } catch(ClassNotFoundException e1){
			 JOptionPane.showConfirmDialog(null,"charge pilote","impossible de charger le driver JdbcOdbcDriver"+e1,JOptionPane.WARNING_MESSAGE);
		 }
		  	//connexion à la base de donnée
		 try{
			 String DBurl ="Jdbc:Odbc:mabase";
			 conn=DriverManager.getConnection(DBurl);
		 }
			 catch(SQLException e2){
				 JOptionPane.showConfirmDialog(null,"connexion db"," impossible de connecter à la base de donnée"+e2,JOptionPane.WARNING_MESSAGE);
			 }
			//Creation et execution de la requete;
		try { 
			Statement stm=conn.createStatement();
			Resultats=stm.executeQuery(requete1);
			JOptionPane.showInternalConfirmDialog(null,"Confirmation.","Le produit "+strDesignation+" a etait bien ajouté",JOptionPane.CANCEL_OPTION);
		}catch(SQLException e3){
			JOptionPane.showConfirmDialog(null,"requete sql","une anomalie conserant la requete sql"+e3,JOptionPane.WARNING_MESSAGE);
 
		}
		 }
 
//********************************************************************************
	  //*****************    bouton rechercher  **********************************	  
	  public void rechercher(ActionEvent a){
		  String strDesignation=txDesignation.getText(), strReference=txReference.getText(),strNUDeSerier=txNUDeSerier.getText(), strTotale=txTotale.getText(), strDateReception=txDateReception.getText(),
		  strRestant=txRestant.getText(), strCosomme=txCosomme.getText(), strDateExpiration=txDateExpiration.getText(),
		  strType=txType.getText(), strTypeChoix=chType.getSelectedItem(), strLaboratoir=chLaboratoir.getSelectedItem(),
		  strMedecin=chMedecin.getSelectedItem(),strCode=txCode.getText();
		   String
		  requete2="SELECT * FROM `produit`WHERE  `designation_pro` LIKE '"+strDesignation+"' or " +
		  		"`reference_pro` LIKE '"+strReference+"' or `numero_pro` LIKE '"+strNUDeSerier+"' or" +
		  		" `type_pro` LIKE '"+strType+"' or `labo_pro` LIKE '"+strLaboratoir+"' or " +"`totale_pro` = "+strTotale+" or `consommer_pro` ="+strCosomme+" or " +
		  		"`restant_pro` ="+strCosomme+" or `dateReception_pro` = '"+strDateReception+"' or " +
		  		"`dateExpiration` = '"+strDateExpiration+"'";
		  Connection conn = null ;
		  ResultSet resultats;
 
 
		  //chargement des driver;
		  try {
			  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
			  }catch (ClassNotFoundException e1){
				  JOptionPane.showConfirmDialog(null,"Driver jdbc","impossible de charger le pilote jdbc:odbc"+e1,JOptionPane.WARNING_MESSAGE);
			 }
			 try{
				 String DBurl ="Jdbc:Odbc:mabase";
				 conn=DriverManager.getConnection(DBurl);
			 }
				 catch(SQLException e2){
					 JOptionPane.showConfirmDialog(null,"connexion db"," impossible de connecter à la base de donnée"+e2,JOptionPane.WARNING_MESSAGE);
				 }
				//Creation et execution de la requete;
			try { 
				Statement stm=conn.createStatement();
				resultats=stm.executeQuery(requete2);
				}catch(SQLException e3){
				JOptionPane.showConfirmDialog(null,"requete sql","une anomalie conserant la requete sql"+e3,JOptionPane.WARNING_MESSAGE);
 
			}
			 }
//***************************************************************************************
	  //*********************  bouron modifeier  ****************************************
	  public void modifier(ActionEvent mo){
		  String strDesignation=txDesignation.getText(), strReference=txReference.getText(),strNUDeSerier=txNUDeSerier.getText(), strTotale=txTotale.getText(), strDateReception=txDateReception.getText(),
		  strRestant=txRestant.getText(), strCosomme=txCosomme.getText(), strDateExpiration=txDateExpiration.getText(),
		  strType=txType.getText(), strTypeChoix=chType.getSelectedItem(), strLaboratoir=chLaboratoir.getSelectedItem(),
		  strMedecin=chMedecin.getSelectedItem(),strCode=txCode.getText();
		  String
		  requete3=" UPDATE `mabase`.`produit` SET `designation_pro` = '"+strDesignation+"',`reference_pro` = '"+strReference+",`numero_pro` = '"+strNUDeSerier+"',`type_pro` = '"+strType+"',`labo_pro` = '"+strTypeChoix+"',`totale_pro` = '"+strTotale+"',`consommer_pro` = '"+strCosomme+"',`restant_pro` = '"+strRestant+"',`dateReception_pro` = '"+strDateReception+"',`dateExpiration` = '"+strDateExpiration+"' WHERE `produit`.`id_pro` ="+strCode+" " ;    
 
		  	Connection conn = null;
		  	ResultSet resultats;
		  //chargement des driver;
		  try {
			  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
			  }catch (ClassNotFoundException e1){
				  JOptionPane.showConfirmDialog(null,"Driver jdbc","impossible de charger le pilote jdbc:odbc"+e1,JOptionPane.WARNING_MESSAGE);
			 }
			 try{
				 String DBurl ="Jdbc:Odbc//localhost:80/mabase";
				 conn=DriverManager.getConnection(DBurl);
			 }
				 catch(SQLException e2){
					 JOptionPane.showConfirmDialog(null,"connexion db"," impossible de connecter à la base de donnée"+e2,JOptionPane.WARNING_MESSAGE);
				 }
				//Creation et execution de la requete;
			try { 
				Statement stm=conn.createStatement();
				resultats=stm.executeQuery(requete3);
				JOptionPane.showInternalConfirmDialog(null,"Confirmation.","Le produit "+strDesignation+" a était bien modifié",JOptionPane.CANCEL_OPTION);
			}catch(SQLException e3){
				JOptionPane.showConfirmDialog(null,"requete sql","une anomalie conserant la requete sql"+e3,JOptionPane.WARNING_MESSAGE);
 
			}
			 }
 
 
	  }