String fromdate =form1.getStartDate() == null ? null : form1.getStartDate(); //开始日期
String enddate =form1.getEndDate() == null ? null :form1.getEndDate(); //截止日期
Hashtable htPara = new Hashtable();
htPara.put("fromdate", ""+fromdate);
htPara.put("enddate", ""+enddate);
htPara.put("ReportTitle", "市政工程信息数据统计表");
htPara.put("foot","");
String reportName = "ManageRoadDigCard"; // 报表名称Civicismproject.jasper
// reportTemplateFile = "reports/ManageRoadDigCard.jasper"; // 报表模板文件
String reportTemplateFile = "reports/Civicismproject.jasper"; // 报表模板文件
// reportURL = "/reports/ManageRoadDigCard.jasper"; // 报表url
String reportURL = "/reports/Civicismproject.jasper"; // 报表url
System.out.println(reportTemplateFile + " on loading...");
ReportTools rt = new ReportTools(reportName, reportTemplateFile,reportURL);
String sql="select dadui_popedom ,count(*) as acount,"
+"(select count(*) from t_shizheng_road_pursue a where type='SZGC' and a.dadui_popedom=c.DADUI_POPEDOM and (END_DATE<"
+" (select sysdate from dual)) group by dadui_popedom"
+" ) as bacount ,(select count(*) from t_shizheng_road_pursue b where type='SZGC' and b.dadui_popedom=c.DADUI_POPEDOM and (END_DATE>="
+" (select sysdate from dual)) group by dadui_popedom"
+" ) as cacount"
+" from t_shizheng_road_pursue c where type='"+type+"' and CREATE_DATE>=to_date('"+fromdate+"','yyyy-mm-dd') and CREATE_DATE<=to_date('"+enddate+"','yyyy-mm-dd') group by dadui_popedom";
byte rtByte[] = rt.executeQueryToReport2(reportName, sql, htPara);
servletResponse.setContentType("application/pdf");
if (!sql.equals(""))
{
servletResponse.setContentLength(rtByte.length);
}
ServletOutputStream ouputStream = servletResponse
.getOutputStream();
ouputStream.write(rtByte, 0, rtByte.length);
ouputStream.flush();
ouputStream.close();
System.out.println(reportTemplateFile + " load complete");
return null;
//executeQueryToReport2 function
public byte[] executeQueryToReport2(String ReportName, String strSql,
Hashtable ReportParameter) throws Exception
{
ResultSet rs = null;
Connection conn = null;
PreparedStatement stmt = null;
try
{
// 构造报表对象
ReportTools rt = new ReportTools(ReportName, ReportTemplateFile,
jasperURL);
// 设置报表参数
Enumeration emu = ReportParameter.keys();
while (emu.hasMoreElements())
{
String key = (String) emu.nextElement();
rt.setParameter(key, ReportParameter.get(key));
}
if (!strSql.equals(""))
{
// 从连接池得到数据库连接
conn = ConnectionFactory.getConnection();
// 查询SQL语句
stmt = conn.prepareStatement(strSql);
rs = stmt.executeQuery();
byte[] bytes = rt.runReportToPdfUseDBSrc2(rs);
return bytes;
}
else
{
byte[] bytes = rt.runReportToPdfNoResultSet();
return bytes;
}
}
catch (Exception ex)
{
ex.printStackTrace();
throw ex;
}
finally
{
if (!strSql.equals(""))
{
ConnectionFactory.dispose(conn, stmt, rs);
}
}
}
posted on 2007-04-18 09:29
NG 阅读(355)
评论(0) 编辑 收藏