Bonjour,

je voudrais récupérer les données contenues dans les jTextField et les insérer dans une base de donnée

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
 
 public Facture(String ncommande ) {
        initComponents();
                setSize(750,750);
        jLabel1.setText("Commande n°"+ncommande);
        StringBuffer tmp = new StringBuffer();
        StringBuffer tmp1 = new StringBuffer();
        StringBuffer tmp2 = new StringBuffer();
            StringBuffer tmp3 = new StringBuffer();
       try 
        { 
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        Connection con = DriverManager.getConnection("jdbc:odbc:Comptoir","","");
        Statement statement = con.createStatement();
        String query = "SELECT * FROM \"Commandes\" Where \"Commandes.N° commande\"="+ncommande;
        ResultSet resultset = statement.executeQuery(query);
        Boolean valide = false ;
        while(resultset.next())
        {                        
             String adresseclient = resultset.getString("Adresse livraison");  
             String codepostal = resultset.getString("Code postal livraison");  
             String villelivraison = resultset.getString("Ville livraison");  
 
                          tmp.append(adresseclient);
                           tmp1.append(codepostal);
                           tmp2.append(villelivraison);
 
        } jTextField6.setText(tmp.toString()); jTextField4.setText(tmp1.toString());jTextField3.setText(tmp2.toString());
 
        con.close();
    }      
    catch( ClassNotFoundException e) 
    {
        System.err.println("Erreur lors du chargement du pilote : " + e);
    }
    catch(SQLException sqle)
    {
        System.err.print("Erreur SQL : " + sqle);
    }
         catch(Exception e)
   {
        System.err.println("Erreur lors du chargement du pilote : " + e);
    }
 
      public void insertion(String num,String add){
                String url = "jdbc:odbc:Comptoir";
            int i =0;
         Connection con = null;
         String sql=null;    
 
         try {Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                          con = DriverManager.getConnection(url,"","");
             Statement stmt = con.createStatement();
             sql = "INSERT INTO Facture (N° commande,Adresse livraison) VALUES ('"+ num + "','"+ add + "')";                         
             int nbb = stmt.executeUpdate(sql);
             if(nbb>0)
                 System.out.println("Requête effectuée");
             else
                 System.out.println("Probléme requête");                       
        }    
        catch(Exception e) {  System.out.println("Exception4");  }
          finally {
         try {con.close();}
        catch(SQLException e) {e.printStackTrace();}
        }
         }
Le problème c'est que ca me met toujours "Exception4"

Merci