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

com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect date value

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

com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect date value: '%-12-31' for column 'dft' at row 1

代码:

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 = Queries.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;
            }

而不是 % 使用 DAYOFMONTH i.e : for day and MONTH 即 :for month ,因为你的 year 值可以是任何东西。所以你的查询将如下所示:

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

检查示例here