0

谁能指导我在 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 = 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;
            }
4

1 回答 1

1

而不是%使用DAYOFMONTH ie : for day 和MONTH ie :for month ,因为您的year值可以是任何值。因此您的查询将如下所示:

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

在此处查看示例

于 2019-08-21T15:59:30.510 回答