Jump to content

Subreport in Main report


visitmathi

Recommended Posts

Hi

I 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.

 

Thanks

Mathi

Code:
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

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...