Describe how to use crystal reports in java.

Describe how to use crystal reports in java.

Install and run crystl32.cox file in \WINNT\System32 folder and specify the sub directory as ‘crystal’ as the output directory.

- Create an object of CrystalReport class.
- Invoke aboutBox() method – for confirmation whether it is loaded properly
- Establish the connection by using setConnect() method.
- Specify the output file format by using setReportFileName() method.
- Execute the query by using setSqlQuery() method.
- Set the number of copies of the report and the printer collation.
- Set the destination file using setDestination() method.
- Specify the file type using setPrintFileType () method.
- Invoke the method pritReport()

The following is the code example
public class CrystalReportExample
{
   private static final String CONNECT_STRING = "DSN=YourDsn";
   private static final String REPORT_FILE_NAME = "FileName.rpt";
   private static final String SQL_QUERY = "select * from YourTable";
   private static final String PRINT_FILE = "YourNewReport.doc";

   public static void main(String args[]) throws Exception
   {
   try
   {
       crystal.CrystalReport report = new crystal.CrystalReport();
       report.aboutBox();
       report.setConnect(CONNECT_STRING); // database connection
       report.setReportFileName(REPORT_FILE_NAME); // name of the report file
       report.setSQLQuery(SQL_QUERY); // query to get the data from the table
       report.setPrinterCopies((short) 1); // number of copies of the report

       // specifying the printer collating sequence

       report.setPrinterCollation(crystal.PrinterCollationConstants.crptDefault);
       report.setDestination(crystal.DestinationConstants.crptToFile); // destination of the report
       report.setPrintFileName(PRINT_FILE); // writing the report into the file
       report.setPrintFileType(crystal.PrintFileTypeConstants.crptWinWord); // the type of the report file
       report.printReport(); // printing the report onto the destination with the specified requirements
   }
   finally
   {
       com.linar.jintegra.Cleaner.releaseAll(); // releasing all report resources.
   }
   }
}
Why java doesn't support multiple inheritance
Java does not support multiple inheritances. To avoid ambiguity problem – Diamonds of Death – and complexity of multiple inheritance...
What is the use of private constructor in Java?
A private constructor is used when there is no requirement of another class to invoke that. It is used mostly in implementing singletons...
Explain how to make a class immutable - Java
In order to make a class immutable, the changing state of the class object must be restricted. This means restricting an assignment to a variable...
Post your comment
Discussion Board
Describe how to use crystal reports in java
In "Describe how to use crystal reports in java" example first line tells

"Install and run crystl32.cox file in \WINNT\System32 folder and specify the sub directory as ‘crystal’ as the output directory."

I installed crystl32.cox in \System32 folder. But i am unable to specify the sub directory as ‘crystal’ as the output directory. How to create this? Please explain and reply me in mail.

I'll be very helpful and thank full to this site if they give me the answer.

Santu 11-15-2012