IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Développement Web en Java Discussion :

Erreur JodaTime application JEE


Sujet :

Développement Web en Java

  1. #1
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2013
    Messages
    174
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val d'Oise (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2013
    Messages : 174
    Points : 51
    Points
    51
    Par défaut Erreur JodaTime application JEE
    Salut ,

    Voila quand je veux ajouter une commande dans la base de donnée depuis mon formulaire formulaire_commande.jsp ca m'affiche une erreur appropos de la date la voici (Image de l'erreur dans la piece jointe) :

    Création de la commande échouécom.commande.dao.DAOException: Ajout de la commande échouécom.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect datetime value: '\xAC\xED\x00\x05sr\x00\x16org.joda.time.DateTime\xB8<xdj[\xDD\xF9\x02\x00\x00xr\x00\x1Forg.joda.time.base.BaseDateTime\xFF\xFF\x' for column 'dateCommande' at row 1

    Dans la console :

    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
    com.commande.dao.DAOException: Ajout de la commande échouécom.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect datetime value: '\xAC\xED\x00\x05sr\x00\x16org.joda.time.DateTime\xB8<xdj[\xDD\xF9\x02\x00\x00xr\x00\x1Forg.joda.time.base.BaseDateTime\xFF\xFF\x' for column 'dateCommande' at row 1
    	at com.commande.dao.CommandeDAOimplement.creerCommande(CommandeDAOimplement.java:52)
    	at com.commande.forms.CommandeForm.FormCommande(CommandeForm.java:81)
    	at com.commande.servlets.CommandeInscription.doPost(CommandeInscription.java:81)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
    	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    	at java.lang.Thread.run(Unknown Source)
    Dans le bean de la Commande , j'ai la date de tyle DateTime :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    private DateTime date_commande;
    Et dans la base de donnée de mySql (version 5.6.12) j'ai aussi l'attribut dateCommande de type DateTime . j'ai changer de forma pattern mais j'ai toujours la meme erreur .

    Code du formulaire :

    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
    <div id="formulaireCommande">
     
     
    <fieldset>
     
     
    <span class="rouge">*</span> Champ obligatoire .
     
     
    <legend>Formulaire de la commande</legend>
     
    <form action="<c:out value="CommandeInscription"/>" method="post">
    ...
     
    <p>Date de la commande : <input type="text" value="<joda:format value="${beanCommande.date_commande}" pattern="YYYY-MM-DD HH:MM:SS"/>" name="dateCommande" disabled="disabled"/></p>
     
    ...
     
    <p><input type="submit" value="Valider la commande"/> <input type="reset" value="Remettre a zero"/></p>
     
    <span class="${empty formCommande.erreurs ? 'vert' : 'rouge'}"><c:out value="${formCommande.resultat}"></c:out></span>
     
    </form>
     
    </fieldset>
     
     
    </div>
    Code de CommandeForm :

    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
    public class CommandeForm {
     
        private String             champ_montant         = "montant";
        private String             champ_modePayement    = "modePayement";
        private String             champ_statusPayement  = "statusPayement";
        private String             champ_modeLivraison   = "modeLivraison";
        private String             champ_statusLivraison = "statusLivraison";
     
        public Map<String, String> erreurs               = new HashMap<String, String>();
     
        public String              resultat;
     
        private CommandeDAO        commandeDAO;
        private ClientDAO          clientDAO;
     
        public CommandeForm( CommandeDAO commandeDAO, ClientDAO clientDAO ) {
            super();
            this.commandeDAO = commandeDAO;
            this.clientDAO = clientDAO;
        }
     
        public Map<String, String> getErreurs() {
            return erreurs;
        }
     
        public String getResultat() {
     
            return resultat;
        }
     
        // methode de la form :
     
        public Commande FormCommande( HttpServletRequest request ) {
     
            String montant = getValueChamp( request, champ_montant );
            String modePayement = getValueChamp( request, champ_modePayement );
            String statusPayement = getValueChamp( request, champ_statusPayement );
            String modeLivraison = getValueChamp( request, champ_modeLivraison );
            String statusLivraison = getValueChamp( request, champ_statusLivraison );
     
            // Form client :
     
            ClientForm form_client = new ClientForm( clientDAO );
     
            Client client = form_client.FormClient( request );
     
            erreurs = form_client.getErreurs();
     
            // //////////////////////*****////////////////////
     
            DateTime dt = new DateTime();
     
            Commande commande = new Commande();
     
            commande.setClient( client );
     
            commande.setDate_commande( dt );
     
            traiterMontant( montant, commande );
            traiterModePayement( modePayement, commande );
            traiterStatusPayement( statusPayement, commande );
            traiterModeLivraison( modeLivraison, commande );
            traiterStatusLivraison( statusLivraison, commande );
            try {
                if ( erreurs.isEmpty() ) {
                    commandeDAO.creerCommande( commande );
                    resultat = "Inscription avec succès";
                } else {
                    resultat = "Inscription échoué";
                }
            } catch ( DAOException e ) {
                setErreurs( "imprévu", "Erreur imprévue lors de la création de la commande" );
                resultat = "Création de la commande échoué" + e;
                e.printStackTrace();
            }
     
            return commande;
     
        }
     
        // les methodes utilitaires :
     
        public void traiterStatusLivraison( String statusLivraison, Commande commande ) {
     
            try {
                validationStatusLivraison( statusLivraison );
            } catch ( FormException e ) {
                setErreurs( champ_statusLivraison, e.getMessage() );
            }
     
            commande.setStatus_livraison( statusLivraison );
     
        }
     
        public void traiterModeLivraison( String modeLivraison, Commande commande ) {
     
            try {
                validationModeLivraison( modeLivraison );
            } catch ( FormException e ) {
                setErreurs( champ_modeLivraison, e.getMessage() );
            }
     
            commande.setMode_livraison( modeLivraison );
     
        }
     
        public void traiterStatusPayement( String statusPayement, Commande commande ) {
     
            try {
                validationStatusPayement( statusPayement );
            } catch ( FormException e ) {
                setErreurs( champ_statusPayement, e.getMessage() );
            }
     
            commande.setStatus_payement( statusPayement );
     
        }
     
        public void traiterModePayement( String modePayement, Commande commande ) {
     
            try {
                validationModePayement( modePayement );
            } catch ( FormException e ) {
                setErreurs( champ_modePayement, e.getMessage() );
            }
     
            commande.setMode_payement( modePayement );
     
        }
     
        public void traiterMontant( String montant, Commande commande ) {
     
            try {
                validationMontant( montant );
            } catch ( FormException e ) {
                setErreurs( champ_montant, e.getMessage() );
            }
     
            commande.setMontant( montant );
     
        }
     
        public void validationStatusLivraison( String statusLivraison ) throws FormException {
            if ( statusLivraison == null ) {
                throw new FormException( "Veuillez entrer la status de livraison" );
            }
        }
     
        public void validationModeLivraison( String modeLivraison ) throws FormException {
            if ( modeLivraison == null ) {
                throw new FormException( "Veuillez entrer le mode de livraison" );
            }
        }
     
        public void validationStatusPayement( String statusPayement ) throws FormException {
            if ( statusPayement == null ) {
                throw new FormException( "Veuillez entrer la status de payement" );
            }
        }
     
        public void validationModePayement( String modePayement ) throws FormException {
            if ( modePayement == null ) {
                throw new FormException( "Veuillez entrer le mode de payement" );
            }
        }
     
        public double validationMontant( String montant ) throws FormException {
     
            double valeur;
     
            if ( montant != null ) {
     
                try {
     
                    valeur = Double.parseDouble( montant );
     
                    if ( valeur < 0 ) {
                        throw new FormException( "Le montant doit etre positive " );
                    }
                } catch ( NumberFormatException e ) {
                    valeur = -1;
                    throw new FormException( "Le montant doit etre un nombre numérique" );
                }
            }
     
            else {
                valeur = -1;
                throw new FormException( "Veuillez entrer un montant" );
            }
     
            return valeur;
     
        }
     
        public void setErreurs( String champ, String message ) {
            erreurs.put( champ, message );
        }
     
        public String getValueChamp( HttpServletRequest request, String champ ) {
            String value = request.getParameter( champ );
     
            if ( value == null || value.trim().length() == 0 ) {
                return null;
            } else {
                return value.trim();
            }
        }
     
    }
    Code list_commande.jsp :

    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
    <div id="tableaCommande">
     
    <c:choose>
     
    <c:when test="${empty sessionScope.sessionCommande}">
     
    <c:out value="Aucune commande n'est valable"></c:out>
     
    </c:when>
     
    <c:otherwise>
     
    <table border="1">
     
    <tr>
     
    <th>Prénom</th>
    <th>Date de la commande</th>
    <th>Montant</th>
    <th>Mode de payement</th>
    <th>Status de payement</th>
    <th>Mode de livraison</th>
    <th>Status de livraison</th>
    <th>Action</th>
    </tr>
     
    <c:forEach items="${sessionScope.sessionCommande}" var="mapCommande">
     
    <tr>
     
    <td>${mapCommande.value.client.prenom}</td>
    <td><joda:format value="${mapCommande.value.date_commande}" pattern="YYYY-MM-DD HH:MM:SS"/></td>
    <td>${mapCommande.value.montant}</td>
    <td>${mapCommande.value.mode_payement}</td>
    <td>${mapCommande.value.status_payement}</td>
    <td>${mapCommande.value.mode_livraison}</td>
    <td>${mapCommande.value.status_livraison}</td>
    <td> <a href="<c:url value="/SupprimerCommande"><c:param name="idCommandeKey" value="${mapCommande.key}"/></c:url>">Supprimer</a>  </td>
    </tr>
     
    </c:forEach>
    </table>
    </c:otherwise>
    </c:choose>
    </div>
    La methode d'ajout :

    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
    public class CommandeDAOimplement implements CommandeDAO {
     
        public static final String sqlInsert    = "insert into commande(idClient,dateCommande,montant,modePayement,statusPayement,modeLivraison,statusLivraison) values(?,?,?,?,?,?,?)";
    public void creerCommande( Commande commande ) throws DAOException {
            Connection connection = null;
            PreparedStatement preparedStatement = null;
            ResultSet resultsetKey = null;
            try {
                connection = daoFactory.getConnection();
                preparedStatement = inisialisationPrepareStatement( connection, sqlInsert, true, commande.getClient()
                        .getId_client(), new Timestamp( commande.getDate_commande().getMillis() ), commande.getMontant(), commande.getMode_payement(),
                        commande.getStatus_payement(), commande.getMode_livraison(), commande.getStatus_livraison() );
     
                int status = preparedStatement.executeUpdate();
     
                if ( status == 0 ) {
                    throw new DAOException( "Aucune ligne commande n'est inserer" );
                }
     
                resultsetKey = preparedStatement.getGeneratedKeys();
     
                if ( resultsetKey.next() ) {
                    commande.setId_commande( resultsetKey.getLong( 1 ) );
                } else {
                    throw new DAOException( "Aucune clé commande n'as étais générer" );
                }
     
            } catch ( SQLException e ) {
                throw new DAOException( "Ajout de la commande échoué" + e );
            } finally {
                fermeture( resultsetKey, preparedStatement, connection );
            }
        }
    }
    Et voila l'image de mon erreur :
    Images attachées Images attachées  

  2. #2
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2013
    Messages
    174
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val d'Oise (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2013
    Messages : 174
    Points : 51
    Points
    51
    Par défaut
    Réponse ?

  3. #3
    Membre du Club
    Inscrit en
    Mars 2010
    Messages
    74
    Détails du profil
    Informations forums :
    Inscription : Mars 2010
    Messages : 74
    Points : 54
    Points
    54
    Par défaut
    Je ne sais pas si c'est correct mais tu peux juste persister deux type de date.

    java.sql.date et java.util.date
    Il faut transformer la date de type joda en java.sql.date ou java.util.date

  4. #4
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2013
    Messages
    174
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val d'Oise (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2013
    Messages : 174
    Points : 51
    Points
    51
    Par défaut
    Citation Envoyé par cyberkamikaz Voir le message
    Je ne sais pas si c'est correct mais tu peux juste persister deux type de date.

    java.sql.date et java.util.date
    Il faut transformer la date de type joda en java.sql.date ou java.util.date
    Je comprend pas bien ce que vous voulez dire ??

Discussions similaires

  1. [MVC] Erreur lors intégration Spring MVC sur une application JEE
    Par khaigo dans le forum Spring Web
    Réponses: 0
    Dernier message: 26/06/2011, 18h04
  2. erreur d'application aléatoire
    Par Galkir dans le forum C++Builder
    Réponses: 3
    Dernier message: 22/06/2006, 15h03
  3. [FB] Gestion des erreurs et application francophone
    Par Benjamin GAGNEUX dans le forum Installation
    Réponses: 10
    Dernier message: 20/05/2006, 14h54
  4. Erreur d'application
    Par the watcher dans le forum Bases de données
    Réponses: 13
    Dernier message: 11/05/2006, 12h29
  5. msimn.exe Erreur d'application
    Par popy29 dans le forum Autres Logiciels
    Réponses: 0
    Dernier message: 31/12/2005, 12h26

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo