Java DB和jasper报告嵌套选择

时间:2016-01-11 18:58:27

标签: java select nested jasper-reports javadb

我创建嵌套的选择视图,以便在JAVA DB的Jasper Netbeans报告中运行,并且需要通过注入select中的CASE或使用{{1}来基于相同的下面的语句区分分组。可以在JAVA DB或其他任何方式使用,最后我想使用记录集作为源查询来运行jasper报告我的代码如下

if

输出结果为:

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
 try {
   String host1= "jdbc:derby://localhost:1527//home/mohamed/java- 
   progs/SPaccounting/accountsdb/accountsdb;create=true";
   String uName1="rootuser";
   String uPass1="1234a1234b";
   con1=DriverManager.getConnection(host1,uName1 ,uPass1);
   String sql1="select sum(journal_amount) AS DR ,0 as CR, journal_crname  AS 
   ACCNAME FROM JOURNAL
   GROUP BY journal_CRNAME UNION select 0 AS DR,sum(journal_amount) AS   CR,  
   journal_dbname AS ACCNAME FROM JOURNAL
   GROUP BY journal_DRNAME order by ACCNAME
   ";
   JasperFillManager.fillReport(jasperReport,param1,connect); //add param    
   if   required    
   String jrxmlFileName = "/home/mohamed/java-progs/accounting syst em/     
   JavaAaccountingsys/src/report1.jrxml";
   JasperDesign jasperDesign = JRXmlLoader.load(jrxmlFileName);


   JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
   JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null,    con1);
   JasperViewer.viewReport(jasperPrint); 
   } catch (JRException e) {
        e.printStackTrace();
   } catch (ClassNotFoundException e) {
        e.printStackTrace();
   } catch (SQLException e) {
    e.printStackTrace();
 }
}

我希望区分并总结以上并从信用ACCNAME DR CR -------- ---- ----- CASH 1,200 0 AMRO BANK 0 500 CASH 0 600 AMRO BANK 700 0 中削减债务DR并获得以下报告的结果:

CR

请协助纠正选择陈述

1 个答案:

答案 0 :(得分:2)

是的我在SO中有正确的select语句,将输出分组到一个嵌套包中,在select语句下面添加报告工作正常 然后创建一个子查询以获得最后一步

SELECT ACCNAME,
CASE WHEN SUM(CREDIT - DEBT) < 0 THEN - SUM(CREDIT - DEBT)
ELSE 0
 END DEBT,
   CASE WHEN SUM(CREDIT - DEBT) > 0 THEN   SUM(CREDIT - DEBT)
        ELSE 0
   END CREDIT
FROM ( ...... ) myTable
GROUP BY ACCNAME ;

因此,我走上了正确的道路。