0

Can anyone guide me to execute query code in a MySQL database, I'm working in a JSP project and when I try to execute the query I get the following exception:

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

Code:

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;
            }

1 Answer 1

1

Instead of % use DAYOFMONTH i.e : for day and MONTH i.e :for month , as your year value can be anything .So your query will look like below :

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

Check example here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.