com.mysql.jdbc.MysqlDataTruncation:数据截断:不正确的日期值

时间:2019-08-21 13:17:21

标签: java maven jsp mysql-workbench mysql-connector

任何人都可以指导我在MySQL数据库中执行查询代码,我在JSP项目中工作,当我尝试执行查询时,出现以下异常:

  

com.mysql.jdbc.MysqlDataTruncation:数据截断:不正确的日期   值:第1行“ dft”列的“%-12-31”

try {

            connexion = ServletCalendrier.getConnexion();

            if(connexion == null){
                System.err.println("Une demande de connexion a ete faite au serveur mais n'a pas abouti");
            }

            initFeries();

            String anneePlus = Integer.parseInt(annee)+1+"%";
            query ="DELETE FROM TgCalFac WHERE annee LIKE '"+anneePlus+"' AND versionFac LIKE '"+version+"' AND dft LIKE '%-12-31'";
            result = Querries.executeQuery(query);

            connexion = ServletCalendrier.getConnexion();
            pstmt = connexion.prepareStatement("SELECT count(*) as nombre FROM TgDft");     
            rset = pstmt.executeQuery();



            if(rset.next())
                nbJoursDft = rset.getInt("nombre");

            pstmt.close();
            pstmt = null;

            // Insertion du premier lot

            dft = new Dft(OperationsSurDates.stringToDate(String.valueOf((Integer.valueOf(annee)-1)) + "-12-31","yyyy-MM-dd"));
            drmf = new Drmf(dft.getDft());

            extraction = new Extraction(drmf);
            ps2 = new PS2(extraction,ps2Prec);
            dateFacture = new DateFacture(ps2);

            delai1 = OperationsSurDates.differenceDates(dateFacture.getDateFacture1(), dft.getDft());
            delai2 = OperationsSurDates.differenceDates(dateFacture.getDateFacture2(), dft.getDft());


            drmf1Type = 0;
            if(drmf.isDrmf1R()){
                drmf1Type = 1;
            }
            if(drmf.isDrmf1L()){
                drmf1Type = 2;
            }

            drmf2Type = 0;
            if(drmf.isDrmf2R()){
                drmf2Type = 1;
            }
            if(drmf.isDrmf2L()){
                drmf2Type = 2;
            }

1 个答案:

答案 0 :(得分:1)

您可以使用%的值代替year的{​​{1}}值,而不是DAYOFMONTH,例如:day和MONTH,例如:month。 :

 query ="DELETE FROM TgCalFac 
        WHERE 
        annee LIKE '"+anneePlus+"' 
        AND 
        versionFac LIKE '"+version+"'
        AND DAYOFMONTH(dft) = 31 AND MONTH(dft) = 12";

检查示例here

相关问题