我打算通過pentaho生成pdf報告。我對pentho RD很陌生。Pentaho report.setQuerty
我能夠通過在prpt中預先配置(dbconntion +查詢和傳遞參數)並從java調用它來生成一個真實的報告。 這很好。
問題:我打算使用report.setQuery(「dummyQuery」,「SELECT NAME,ID FROM test.person」); //一些查詢來動態生成報告。 如果這是可能的..?
當我使用report.setQuery與相同的查詢,我的報告生成一個空白pdf? 我想我應該配置一個HQL數據源..來實現這一目標?
pre-config PRPT - Im顯示2個值,名稱和ID。
我能夠通過傳遞參數動態生成此pdf。
請大家幫忙動態生成這個PDF格式你的setQuery或「如何使用setQuery」。
我真的很想學習生成pentaho pdf報告。
package com.report;
import java.io.File;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.pentaho.reporting.engine.classic.core.ClassicEngineBoot;
import org.pentaho.reporting.engine.classic.core.MasterReport;
import org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.PdfReportUtil;
import org.pentaho.reporting.libraries.resourceloader.Resource;
import org.pentaho.reporting.libraries.resourceloader.ResourceManager;
/**
* Servlet implementation class Generate
*/
@WebServlet("/Generate")
public class Generate extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public Generate() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
try{
response.reset();
response.setContentType("application/pdf");
ClassicEngineBoot.getInstance().start();
ResourceManager manager = new ResourceManager();
manager.registerDefaults();
String PrptPath ="C:\\Users\\3692902\\Desktop\\pentahoTest.prpt";
//generate report through pre-configured prpt (db connection + query)
Resource res = manager.createDirectly(new File(PrptPath), MasterReport.class);
MasterReport report = (MasterReport) res.getResource();
report.getParameterValues().put("IDValue",101);
//generate report through query?????
//report.setQuery("SELECT ID FROM test.person");
PdfReportUtil.createPDF(report,response.getOutputStream());
}
catch(Exception e){
e.printStackTrace();
}
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
}