[英]Report with JasperReports with database connection
I'm trying to make a report with JasperReports containing the result of the queries to a database. 我正在尝试使用JasperReports生成一个报告,其中包含对数据库的查询结果。 I followed some tutorials and I wrote the code.
我遵循了一些教程,并编写了代码。 The part which the database connection it's ok, it works:
数据库连接可以的部分,它可以正常工作:
"Get connection ... Get connection oracle.jdbc.driver.************ Done!", but when I'm trying to run the class with the report, I face some exceptions: “获取连接...获取连接oracle.jdbc.driver。************完成!”,但是当我尝试使用报表运行该类时,我遇到了一些异常:
1) Exception in thread "main" net.sf.jasperreports.engine.JRException: Error compiling report java source files : E:\\Fc\\Java\\hws\\L9again\\StyledTextReport_1462019818479_424906.java; 1)线程“主”中的异常net.sf.jasperreports.engine.JRException:编译报告Java源文件时出错:E:\\ Fc \\ Java \\ hws \\ L9again \\ StyledTextReport_1462019818479_424906.java;
2)Caused by: java.io.IOException: Cannot run program "javac": CreateProcess error=2, The system cannot find the file specified; 2)由以下原因引起:java.io.IOException:无法运行程序“ javac”:CreateProcess error = 2,系统找不到指定的文件;
3)Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified. 3)由以下原因引起:java.io.IOException:CreateProcess错误= 2,系统找不到指定的文件。
My code for the part with the report is: 我的报告部分代码是:
package org.o7;
import java.io.File;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.export.JRPdfExporter;
import net.sf.jasperreports.export.ExporterInput;
import net.sf.jasperreports.export.OutputStreamExporterOutput;
import net.sf.jasperreports.export.SimpleExporterInput;
import net.sf.jasperreports.export.SimpleOutputStreamExporterOutput;
import net.sf.jasperreports.export.SimplePdfExporterConfiguration;
public class JavaCallJasperReport {
public static void main(String[] args) throws JRException,
ClassNotFoundException, SQLException {
String reportSrcFile = "C:/jasperreport/StyledTextReport/StyledTextReport.jrxml";
// First, compile jrxml file.
JasperReport jasperReport = JasperCompileManager.compileReport(reportSrcFile);
Connection conn = ConnectionUtils.getConnection();
// Parameters for report
Map<String, Object> parameters = new HashMap<String, Object>();
JasperPrint print = JasperFillManager.fillReport(jasperReport,
parameters, conn);
// Make sure the output directory exists.
File outDir = new File("C:/jasperoutput");
outDir.mkdirs();
// PDF Exportor.
JRPdfExporter exporter = new JRPdfExporter();
ExporterInput exporterInput = new SimpleExporterInput(print);
// ExporterInput
exporter.setExporterInput(exporterInput);
// ExporterOutput
OutputStreamExporterOutput exporterOutput = new SimpleOutputStreamExporterOutput(
"C:/jasperoutput/FirstJasperReport.pdf");
// Output
exporter.setExporterOutput(exporterOutput);
//
SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();
exporter.setConfiguration(configuration);
exporter.exportReport();
System.out.print("Done2!");
}
}
Can anyone tell me what can I do to solve this? 谁能告诉我该怎么解决?
请尝试将jdt-compiler.jar放在您的classpath中。如果这样做有问题,请告诉我
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.