codice:
<%@page import="com.businessobjects.samples.JRCHelperSample,
com.crystaldecisions.reports.sdk.ReportClientDocument,
com.crystaldecisions.sdk.occa.report.application.OpenReportOptions,
com.crystaldecisions.sdk.occa.report.lib.ReportSDKExceptionBase,
java.sql.Connection,
java.sql.DriverManager,
java.sql.ResultSet,
java.sql.SQLException,
java.sql.Statement"%><%
// This sample code calls methods from the JRCHelperSample class, which
// contains examples of how to use the BusinessObjects APIs. You are free to
// modify and distribute the source code contained in the JRCHelperSample class.
try {
String reportName = "CrystalReport1.rpt";
ReportClientDocument clientDoc = (ReportClientDocument) session.getAttribute(reportName);
if (clientDoc == null) {
// Report can be opened from the relative location specified in the CRConfig.xml, or the report location
// tag can be removed to open the reports as Java resources or using an absolute path
// (absolute path not recommended for Web applications).
clientDoc = new ReportClientDocument();
// Open report
clientDoc.open(reportName, OpenReportOptions._openAsReadOnly);
// ****** BEGIN POPULATE WITH RESULTSET SNIPPET ****************
{
// **** POPULATE MAIN REPORT ****
{
// Connection Info for fetching the resultSet
String connectStr = "jdbc:microsoft:sqlserver://localhost:1433;databaseName=Giulio2";
String driverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String userName = "xx"; // TODO: Fill in database user
String password = "xxxxxx"; // TODO: Fill in valid password
// TODO: Ensure this query is valid in your database. An exception will be thrown otherwise.
String query = "SELECT CITTADINANZA FROM ANAGRAFICA_PUERPERA";
// As long the Resultset schema has the same field names and types,
// then the Resultset can be used as the datasource for the table
String tableAlias = "Anagrafica_puerpera"; // TODO: Change to correct table alias
// Push the Java ResultSet into the report (this will then be the datasource of the report)
JRCHelperSample.passResultSet(clientDoc, fetchResultSet(driverName, connectStr, userName, password, query),
tableAlias, "");
}
// **** POPULATE MAIN REPORT ****
{
// Connection Info for fetching the resultSet
String connectStr = "jdbc:microsoft:sqlserver://localhost:1433;databaseName=Giulio2";
String driverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String userName = "xx"; // TODO: Fill in database user
String password = "xxxxx"; // TODO: Fill in valid password
// TODO: Ensure this query is valid in your database. An exception will be thrown otherwise.
String query = "SELECT PROVINCIA FROM ANAGRAFICA_STRUTTURE_OSPEDALIERE";
// As long the Resultset schema has the same field names and types,
// then the Resultset can be used as the datasource for the table
String tableAlias = "Anagrafica_strutture_ospedaliere"; // TODO: Change to correct table alias
// Push the Java ResultSet into the report (this will then be the datasource of the report)
JRCHelperSample.passResultSet(clientDoc, fetchResultSet(driverName, connectStr, userName, password, query),
tableAlias, "");
}
// **** POPULATE MAIN REPORT ****
{
// Connection Info for fetching the resultSet
String connectStr = "jdbc:microsoft:sqlserver://localhost:1433;databaseName=Giulio2";
String driverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String userName = "xx"; // TODO: Fill in database user
String password = "xxxxxx"; // TODO: Fill in valid password
// TODO: Ensure this query is valid in your database. An exception will be thrown otherwise.
String query = "SELECT MEDICO FROM CEDAP";
// As long the Resultset schema has the same field names and types,
// then the Resultset can be used as the datasource for the table
String tableAlias = "CedAP"; // TODO: Change to correct table alias
// Push the Java ResultSet into the report (this will then be the datasource of the report)
JRCHelperSample.passResultSet(clientDoc, fetchResultSet(driverName, connectStr, userName, password, query),
tableAlias, "");
}
// **** POPULATE MAIN REPORT ****
{
// Connection Info for fetching the resultSet
String connectStr = "jdbc:microsoft:sqlserver://localhost:1433;databaseName=Giulio2";
String driverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String userName = "xx"; // TODO: Fill in database user
String password = "xxxxxx"; // TODO: Fill in valid password
// TODO: Ensure this query is valid in your database. An exception will be thrown otherwise.
String query = "SELECT NOME_MADRE FROM DICHIARAZIONE_NASCITA";
// As long the Resultset schema has the same field names and types,
// then the Resultset can be used as the datasource for the table
String tableAlias = "Dichiarazione_nascita"; // TODO: Change to correct table alias
// Push the Java ResultSet into the report (this will then be the datasource of the report)
JRCHelperSample.passResultSet(clientDoc, fetchResultSet(driverName, connectStr, userName, password, query),
tableAlias, "");
}
}
// ****** END POPULATE WITH RESULTSET SNIPPET ****************
// Store the report document in session
session.setAttribute(reportName, clientDoc);
}
} catch (ReportSDKExceptionBase e) {
out.println(e);
} catch (SQLException e) {
out.println(e);
}
%><%!
// Simple utility function for obtaining result sets that will be pushed into the report.
// This is just standard querying of a Java result set and does NOT involve any
// Crystal JRC SDK functions.
private static ResultSet fetchResultSet(String driverName,
String connectStr, String userName, String password, String query) throws SQLException, ClassNotFoundException {
//Load JDBC driver for the database that will be queried
Class.forName(driverName); ----> riga 139;
Connection connection = DriverManager.getConnection(connectStr, userName, password);
Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
//Execute query and return result sets
return statement.executeQuery(query);
}%>