net.sf.jasperreports.engine.JRException:执行SQL语句时出错:null

时间:2018-12-15 11:30:37

标签: java jasper-reports

我正在尝试通过Jasper报告显示两个日期之间的数据 这些是我的代码:

    String date1=jDateChooser1.getDateFormatString();
    String date2=jDateChooser2.getDateFormatString();
    try {

        Connection conn = null;

        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    } catch (ClassNotFoundException ex) {
        Logger.getLogger(facilitiReports.class.getName()).log(Level.SEVERE, null, ex);
    }

    String url = "jdbc:sqlserver://localhost:1433;databaseName=bradb";
    Connection conn = null;
    try {
        conn = DriverManager.getConnection(url, "sa", "oraclee");
    } catch (SQLException ex) {
        Logger.getLogger(facilitiReports.class.getName()).log(Level.SEVERE, null, ex);
    }

    JasperDesign jd = null;
    try {
        jd = JRXmlLoader.load("D:\\NetBeansProjects\\bra\\src\\facilitiReport.jrxml");
    } catch (JRException ex) {
        Logger.getLogger(facilitiReports.class.getName()).log(Level.SEVERE, null, ex);
    }

    String sql="SELECT * FROM facilitiTable WHERE facilitiDate BETWEEN='" + date1+ "' AND '" + date2+ "' ";
    JRDesignQuery newq=new JRDesignQuery();
    newq.setText(sql);

    jd.setQuery(newq);
    JasperReport jr = null;
    try {
        jr = JasperCompileManager.compileReport(jd);

    } catch (JRException ex) {
        Logger.getLogger(facilitiReports.class.getName()).log(Level.SEVERE, null, ex);
    }

    JasperPrint jp = null;
    try {
        jp = JasperFillManager.fillReport(jr, null, conn);
    } catch (JRException ex) {
        Logger.getLogger(facilitiReports.class.getName()).log(Level.SEVERE, null, ex);
    }

    JasperViewer.viewReport(jp);
    try {

            conn.close();

        } catch (SQLException ex) {
            Logger.getLogger(facilitiReports.class.getName()).log(Level.SEVERE, null, ex);
        }

出现的错误是:

  

net.sf.jasperreports.engine.JRException:执行SQL语句时出错:null       在net.sf.jasperreports.engine.query.JRJdbcQueryExecuter.createDatasource(JRJdbcQueryExecuter.java:240)在net.sf.jasperreports.engine.query.JRJdbcQueryExecuter.createDatasource(JRJdbcQueryExecuter.java:240)       在net.sf.jasperreports.engine.fill.JRFillDataset.createQueryDatasource(JRFillDataset.java:1087)       在net.sf.jasperreports.engine.fill.JRFillDataset.initDatasource(JRFillDataset.java:668)       在net.sf.jasperreports.engine.fill.JRBaseFiller.setParameters(JRBaseFiller.java:1281)       在net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:900)       在net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:845)       在net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:61)       在net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:446)       在net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:849)

1 个答案:

答案 0 :(得分:0)

完成了, 错误出现在这两行:

this.setState((state)=>{
   // some code here

   const newState = [...state.list]
   return {
      list: newState
   }
})

和最终代码为:

String date1=jDateChooser1.getDateFormatString();
String date2=jDateChooser2.getDateFormatString();