`
mimang2007110
  • 浏览: 233494 次
  • 性别: Icon_minigender_1
  • 来自: 西安
社区版块
存档分类
最新评论

Java操作水晶报表

阅读更多

Java操作水晶报表DAO类:

public static ResultSet getResultSet(final int scrollType) {
		ResultSet resultSet = null;
		String query = "";
		try {
			Connection conn = DBConnection.getConnection();
			String sql = "select * from table1";
			resultSet = conn.createStatement().executeQuery(sql);
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
		return resultSet;
	}

 

Action类如下:

public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		operatorName = request.getParameter("operatorName");
		httpSession = request.getSession();
		boolean flag = this.ReportSourceInSession("reportSource", httpSession);

		if (true) {
			request.setAttribute("field", this.setOperator("operator", operatorName, ""));
			return mapping.findForward("success");
		} else
			return mapping.findForward("error");
	}

	public boolean ReportSourceInSession(String session_name,
			HttpSession session) {
		boolean flag = false;
		try { 

			ReportClientDocument reportClientDoc = new ReportClientDocument();
			reportClientDoc.open("result.rpt", 0);
			ResultSet resultSet = CrytalReport
					.getResultSet(ResultSet.TYPE_SCROLL_INSENSITIVE);
			String tableAlias = reportClientDoc.getDatabaseController()
					.getDatabase().getTables().getTable(0).getAlias();
			reportClientDoc.getDatabaseController().setDataSource(resultSet,
					tableAlias, "reportSource");
			session.setAttribute(session_name, reportClientDoc
					.getReportSource());		
			flag = true;
			return flag;
		} catch (Exception e) {
			System.out.println(e.getMessage());
			return flag;
		}
	}

 

JSP页面内容如下:

<%@page import="com.crystaldecisions.report.web.viewer.*,com.crystaldecisions.sdk.occa.report.data.Fields"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>Result</title>
	</head>
	<body>
		<%  
			Object reportSource = session.getAttribute("reportSource");
			CrystalReportViewer crViewer = new CrystalReportViewer();
			crViewer.setOwnPage(true);
			crViewer.setOwnForm(true);
			crViewer.setReportSource(reportSource);
			crViewer.setPrintMode(CrPrintMode.ACTIVEX);
			crViewer.setParameterFields((Fields)request.getAttribute("field"));
			crViewer.setEnableParameterPrompt(false);
			crViewer.processHttpRequest(request, response, this
					.getServletConfig().getServletContext(), null);
		%>
	</body>
</html>

 

 

 

 

 

 

 

 

分享到:
评论
1 楼 baiyuxiong 2010-10-19  
哥,你写的太好了,太有用了!!  

相关推荐

Global site tag (gtag.js) - Google Analytics