bonjour tous le monde
j'ai un probleme d'insertion dans ma base de donné Mysql
lorsque je remplie le formulaire et je le valide un message personnalié s'affiche en disant que :
la source de donné ne peut pas etre créé
et pourtant je n'ai pas de probleme dans les autres formulaire et ce le meme code que dans les autres action que je l'ai employé dans l'action d'insertion

voici les codes
strut-config.xml:
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
 
 
<data-sources>
        <data-source type="org.apache.commons.dbcp.BasicDataSource" key="metale">
            <set-property property="driverClassName" value="com.mysql.jdbc.Driver" />
            <set-property property="url" value="jdbc:mysql://localhost:3306/metal" />
            <set-property property="username" value="root" />
            <set-property property="password" value="jemil" />
            <set-property property="minCount" value="1"></set-property>
            <set-property property="maxCount" value="40"></set-property>
        </data-source>
    </data-sources>
<form-bean name="inserer" type="org.apache.struts.validator.DynaValidatorForm">
            <form-property name="matricule" type="java.lang.String" initial=""/>
            <form-property name="marque" type="java.lang.String" initial=""/>
            <form-property name="genre" type="java.lang.String" initial=""/>
            <form-property name="capacite" type="java.lang.String" initial=""/>
            <form-property name="type" type="java.lang.String" initial=""/>
            <form-property name="d_prem" type="java.lang.String" initial=""/>
            <form-property name="vidange" type="java.lang.String" initial=""/>
            <form-property name="chauffeur" type="java.lang.String" initial=""/>
            <form-property name="permis" type="java.lang.String" initial=""/>
            <form-property name="assur" type="java.lang.String" initial=""/>
            <form-property name="d_assur" type="java.lang.String" initial=""/>
            <form-property name="visite" type="java.lang.String" initial=""/>
            <form-property name="d_visite" type="java.lang.String" initial=""/>
             <form-property name="huile" type="java.lang.String" initial=""/>
        </form-bean>
le code java/
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
 
/*
 * InsererClientsAction.java
 *
 * Created on 8 juillet 2007, 16:50
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
 
package gestion.client;
 
 
import java.io.IOException;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import java.sql.*;
import java.util.ArrayList;
import javax.sql.*;
 
public class InsererClientsAction extends Action {
 
  public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 
    DataSource dataSource;
    DynaActionForm formulaire=(DynaActionForm)form;
        String DEFAULT="DEFAULT";
        String matricule=(String)formulaire.get("matricule");
        String marque=(String)formulaire.get("marque");
        String genre=(String)formulaire.get("genre");
        String capacite=(String)formulaire.get("capacite");
        String type=(String)formulaire.get("type");
        String d_prem=(String)formulaire.get("d_prem");
        String vidange=(String)formulaire.get("vidange");
        String huile=(String)formulaire.get("huile");
        String chauffeur=(String)formulaire.get("chauffeur");
        String permis=(String)formulaire.get("permis");
        String assur=(String)formulaire.get("assur");
        String d_assur=(String)formulaire.get("d_assur");
        String visite=(String)formulaire.get("visite");
        String d_visite=(String)formulaire.get("d_visite");
 
     dataSource = (DataSource)servlet.getServletContext().getAttribute("metale");
     if (dataSource == null) {
         ActionErrors erreurs = new ActionErrors();
         erreurs.add("metale", new ActionError("erreur.metale"));
         this.saveErrors(request, erreurs);
         return mapping.findForward("afficherErreurs");
     }
     Connection connexion = null;
     Statement st = null;
     ResultSet rs = null;
     String requête = null;
 
    try {
 
        connexion = dataSource.getConnection();
 
        requête = "insert into client (matricule,marque,genre,capacite_reservoir,type_client,km_vidange,chauffeur_defaut,type_permis,num_assurance,date_assurance,num_visite,date_fin_visite,km_huile,date_prem_permis,archive_client) values ('','"+matricule+"','"+marque+"','"+genre+"','"+capacite+"','"+type+"','"+vidange+"','"+chauffeur+"','"+permis+"','"+assur+"','"+d_assur+"','"+visite+"','"+d_visite+"','"+huile+"','"+d_prem+"','"+DEFAULT+"')";
 
        st = connexion.createStatement();
        st.executeUpdate(requête);
        rs.close();
        st.close();
    } 
    catch (Exception ex) {
        ActionErrors erreurs = new ActionErrors();
        erreurs.add("metale", new ActionError("erreur.metale","Erreur d'accès à la base des clients"));
        this.saveErrors(request, erreurs);
        return mapping.findForward("afficherErreurs");
    }
    finally {
        try {
            connexion.close();
        }
        catch (Exception ignored) {
        }
    }
// c'est bon
    return mapping.findForward("insertionSucc");
} //execute
} //classe