Domanda

Is there any syntax error in this code or query because i am not getting the required report? I have created a JFrame with JDatechoosr. When i select the dates and click view report, it gives me empty report while i know there is data within the specified date range. I am using MYSQL DB and Netbeans. Kindly help me.

try{
        JasperDesign jd = JRXmlLoader.load("Purchase.jrxml");
        String sql = "select * from purchase where purchase_date between "
                + "'"+DateChooser_frm.getDate().toString()+"' and'"+DateChooser_to.getDate().toString()+"'";
        JRDesignQuery query = new JRDesignQuery();
        query.setText(sql);
        jd.setQuery(query);
        JasperReport jr = JasperCompileManager.compileReport(jd);
        JasperPrint jp = JasperFillManager.fillReport(jr, null,con);
        JasperViewer.viewReport(jp,false);
    }
    catch(JRException ex){
        JOptionPane.showMessageDialog(null, ex);
    }
    catch(Exception ex){
        JOptionPane.showMessageDialog(null, ex);
    }
È stato utile?

Soluzione

You should first take into consideration that Mysql's default date format is YYYY-MM-DD HH:MM:SS. So if you are not giving the dates in this format, you will not get anything from the database. First set your date formats to match the mysql's format and then try to execute the query. You can use 'SimpleDateFormat' to do this.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top