Comment ajouter la valeur séléctionnnée comboBox dans la base de données



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
JButton btnAjouter = new JButton("Ajouter");
 
		btnAjouter.addActionListener(new ActionListener() {
 
 
			public void actionPerformed(ActionEvent arg0) {
				Connection connection;
				java.sql.Statement statement ;
			      connection = null;
			      try
			      {
			    	 try {
						Class.forName("org.sqlite.JDBC");
					} catch (ClassNotFoundException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
			    	 connection = DriverManager.getConnection("jdbc:sqlite:C:\\Users\\tosiba\\eclipse-workspace\\training1\\src\\BDD.db");
 
			    	 JComboBox comboBox = new JComboBox();
 
			    	 		String value = comboBox.getSelectedItem().toString();
 
 
			 statement = connection.createStatement();
			  statement.executeUpdate("INSERT INTO Client ( Nom , Prenom, Versement, Num , Nom_du_projet, idbloc , Date_de_versement ,Date_de_naissance ,  Adresse , Type_de_logement) VALUES('"+nom.getText()+"','"+prenom.getText()+"',"+ versement.getText()+","+ num.getText()+",'"+nomprojet.getText()+  "','"+ idbloc.getText()+"','"   +date.getText()+"',"+  datenaissance.getText()+ ",'"+adresse.getText()+"', ' " + comboBox.getSelectedItem().toString()  + "')" );
 
			  JOptionPane.showMessageDialog(null, "Element ajouté");
 
 
			    statement.close();
			    connection.close();  .....