visitmathi Posted March 24, 2010 Share Posted March 24, 2010 HiI am having sub report, which uses database to retrieve values.I am having main report, which is also doing same thing.While we call individually using java code,it works.But when we add subreport in mainreport,it doesnot retrieve value for sub report. ThanksMathiCode:try{ connection = establishConnection(); System.out.println(connection); statement = connection.createStatement(); resultSet = statement.executeQuery(query); JRResultSetDataSource resultSetDataSource = new JRResultSetDataSource(resultSet); HashMap<String, String> jasperParameter = new HashMap(); jasperReport = JasperCompileManager.compileReport("D:\\Mathi_New\\Test-Java\\TestMathi.jrxml"); jasperParameter.put("SUBREPORT_DIR","D:/Mathi_New/Test-Java/" ); System.out.println("Error1...."); jasperPrint = JasperFillManager.fillReport(jasperReport,jasperParameter, resultSetDataSource); System.out.println("Error2...."); JasperExportManager.exportReportToPdfFile(jasperPrint, "D:\\Mathi_New\\Test-Java\\TestMathi.pdf"); resultSet.close(); statement.close(); connection.close(); } Link to comment Share on other sites More sharing options...
visitmathi Posted March 25, 2010 Author Share Posted March 25, 2010 This can be resolved by passing sub report connection as parameter and mainreport data as resultset. Code:try{ connection = establishConnection(); connection1 = establishConnection(); System.out.println(connection); System.out.println(connection1); statement = connection.createStatement(); resultSet = statement.executeQuery(query); JRResultSetDataSource resultSetDataSource = new JRResultSetDataSource(resultSet); HashMap<String,Object> jasperParameter = new HashMap<String, Object>(); jasperReport = JasperCompileManager.compileReport("D:\\Mathi_New\\Test-Java\\TestMathi.jrxml"); jasperParameter.put("REPORT_CONNECTION",connection1); System.out.println("Out..1...."); //jasperPrint = JasperFillManager.fillReport(jasperReport,jasperParameter, connection); jasperPrint = JasperFillManager.fillReport(jasperReport,jasperParameter, resultSetDataSource); System.out.println("Out..2...."); JasperExportManager.exportReportToPdfFile(jasperPrint, "D:\\Mathi_New\\Test-Java\\TestMathi.pdf"); resultSet.close(); statement.close(); connection.close(); connection1.close(); } Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now