我知道我的Jasper报告正在从我的数据库正确读取,因为它与我的数据库具有相同的行数。但是,它使用" null"填充所有参数。为什么要这样做?
我的代码:
Connection connection;
Statement stmt;
ResultSet rs;
try {
String query = "SELECT CertificateCode, FirstName, LastName, IssueDate, ExpirationDate, Used FROM giftcertificates";
//System.out.println("Query created. Connecting to driver...");
Class.forName("org.h2.Driver");
//System.out.println("Connected to driver. Establishing connection to database...");
connection = DriverManager.getConnection("jdbc:h2:./GiftCertificateManagerDatabase;AUTO_SERVER=TRUE");
//System.out.println("Database connection established. Creating statement...");
stmt = connection.createStatement();
//System.out.println("Statement created. Executing query...");
rs = stmt.executeQuery(query);
//System.out.println("Query executed. Creating data source with result set...");
JRResultSetDataSource rsdt = new JRResultSetDataSource(rs);
//System.out.println("Jasper Report data source created.");
//System.out.println("Creating JasperReport and JasperPrint...");
JasperReport jasperReport;
JasperPrint jasperPrint;
//System.out.println("JasperReport and JasperPrint created. Compiling report...");
jasperReport = JasperCompileManager.compileReport("Reports/GiftCertificateReport.jrxml");
//System.out.println("Report compiled. Filling report with appropriate information...");
jasperPrint = JasperFillManager.fillReport(jasperReport, new HashMap(), rsdt);
//System.out.println("Report filled. Creating viewer...");
JasperViewer view = new JasperViewer(jasperPrint);
//System.out.println("Viewer created. Preparing to display...");
view.setVisible(true);
//System.out.println("Viewer displayed. Preparing to close connection...");
System.out.println(rs);
connection.close();
//System.out.println("Connection closed.");
} catch (ClassNotFoundException | SQLException | JRException ex) {
ex.printStackTrace();
}
答案 0 :(得分:0)
我认为Jasper正在使用null填充所有参数,因为您将空映射传递给fill方法:
jasperPrint = JasperFillManager.fillReport(jasperReport, new HashMap(), rsdt);
你必须用你想要的参数填充那个HashMap。