Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

The Low-Cost Solution for Serving Crystal Reports from a Java Server : Page 2

Delivering Crystal Reports on the Web via commercial platforms can be pricey. The Crystal Reports Java Reporting Component library offers a cheaper solution: deploying Crystal Reports as a component on an open source Java Web server.


advertisement

Create the Report

With all of the setup out of the way, creating the report and connecting to a JDBC-compliant data source is actually a simple, two-step process:
  1. Design the report in Crystal as usual
  2. Use a JDBC database connection from within Crystal

When setting up your report, use a JDBC/JNDI database connection. Begin by selecting "JDBC/JNDI" under the "Create New Connection" folder (either via the Report Wizard or the Database Expert). Fill out the necessary JDBC connection information in the new connection form. (Figure 1 shows an example of how to do this for an Oracle database.) Click "Next" and then supply the UserID and password for connecting to the database, if required.

Click to enlarge

Figure 1. New JDBC Connection for an Oracle Database



Once connected to the database, specify which tables you want to pull from for the report, which columns to include, and how the fields should be grouped/sorted (these steps are no different from how you handle standard data source definitions within Crystal).

The report is now ready to go. You can test it within Crystal and play with it to ensure that the report is formatted to your liking. Once you are satisfied with the report format and data configuration, you are ready to save the report and move on to the Java Web development and application deployment.

Write the Java Code

Once you start a JSP page, which you can do with a couple of imports:

<%@ page import="com.crystaldecisions.reports.reportengineinterface.*, com.crystaldecisions.report.web.viewer.*" %>

You can display a Crystal report via the JSP page in as few as four API calls to the JRC library:

<% CrystalReportViewer crv = new CrystalReportViewer(); JPEReportSourceFactory jrsf = new JPEReportSourceFactory(); crv.setReportSource( jrsf.createReportSource( "MyReport.rpt", request.getLocale() ) ); crv.processHttpRequest( request, response, application, null ); %>

The above code should work unaltered in your environment except for the report name (the first parameter passed into the createReportSource() method), which you need to change to the name you gave the report when you saved it. Also, the code is compatible with both Crystal X and Crystal XI. A more advanced approach using the ReportClientDocument API is available for Crystal XI (see the whitepaper "Crystal Reports XI for J2EE Startup Guide" (PDF) on the Business Objects developer site for details).



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap