我在验证表格时得到了这个例外,

dao.DAOException: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect datetime value: '\xAC\xED\x00\x05sr\x00\x1Acom.sun.jmx.snmp.Timestamp\xFC\xA2\x9Fq\xB8z\xE9!\x02\x00\x04J\x00\x06crtimeJ\x00\x09sysUpTimeL\x00\x0' for column 'date' at row 1
at dao.CommandeDaoImpl.creer(CommandeDaoImpl.java:55)
at forms.InscriptionCommandeForm.inscrireCommande(InscriptionCommandeForm.java:95)
at servlets.Commande.doPost(Commande.java:50)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)


有关类CommandeDaoImpl的代码部分:

public void creer(CommandeBean commande) throws DAOException {
    Connection connexion = null;
    PreparedStatement preparedStatement = null;
    ResultSet valeurAutoGenerees = null;
    try{
        connexion = daoFactory.getConnection();
        preparedStatement = DAOUtilitaire.initialisationRequetePreparee(
                connexion, SQL_INSERT, true, commande.getClient().getId(),
                new Timestamp( commande.getDate().getMillis()),
                commande.getMontant(), commande.getModePaiement(), commande.getStatutPaiement(),
                commande.getModeLivraison(), commande.getStatutLivraison());

        int statut = preparedStatement.executeUpdate();
        if(statut == 0){
            throw new DAOException("Echec de la creation de la commande, aucune ligne ajoutée dans la table.");
        }
        valeurAutoGenerees = preparedStatement.getGeneratedKeys();
        if(valeurAutoGenerees.next()){
            commande.setId( valeurAutoGenerees.getLong(1));
        }else{
            throw new DAOException("Échec de la création de la commande en base,"
                    + " aucun ID auto-généré retourné.");
        }
    }catch(SQLException e){
        throw new DAOException(e);
    }finally{
        DAOUtilitaire.fermeturesSilencieuses(valeurAutoGenerees, preparedStatement, connexion);
    }
}


注意:这两个ligne涉及两个不同项目的两类:
在forms.InscriptionCommandeForm.inscrireCommande(InscriptionCommandeForm.java:95)
在servlets.Commande.doPost(Commande.java:50)

编辑:

    SQL_INSERT = "INSERT INTO commande (
id_client,
date,
montant,
mode_paiement,
statut_paiement,
mode_livraison,
statut_livraison)
VALUES (?, ?, ?, ?, ?, ?, ?)";




       CREATE TABLE tp_sdzee.Commande (
    id INT( 11 ) NOT NULL AUTO_INCREMENT,
    id_client INT( 11 ),
    date DATETIME NOT NULL,
    montant DEC( 11 ) NOT NULL,
    mode_paiement VARCHAR( 20 ) NOT NULL,
    statut_paiement VARCHAR( 20 ),
    mode_livraison VARCHAR( 20 ) NOT NULL,
    statut_livraison VARCHAR( 20 ),
    PRIMARY KEY ( id ),
    CONSTRAINT fk_id_client FOREIGN KEY (id_client) REFERENCES Client(id) ON DELETE SET NULL )
ENGINE = INNODB;

最佳答案

嘿,您必须检查您的时间戳

java.sql.Timestamp


他们的错误如下:(它们的日期值太错误了)。

com.sun.jmx.snmp.Timestamp .


following link as to click

10-07 19:33
查看更多