Java操作水晶レポート
Javaアクション水晶レポートDAOクラス:
アクションクラスは次のとおりです.
JSPページの内容は以下の通りです.
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;
}
アクションクラスは次のとおりです.
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>