Using class file as a data source via OOJDBC

This example shows how to generate the ODF file in a different way using the file demo.zip in <install_root>\help\samples\OOJDBC, which contains all the necessary classes and methods needed for making the OOJDBC data source work with Java objects.

Preparations

Before the OOJDBC data source works with Java objects, you should do the preparations, which are detailed in the following two steps:

  1. You should define a class that specifies the column name and the method of getting data from this column. In this example, the class Products.java in demo.zip takes this role. This class file contains the method public int getProductID(), which implies that the column name is ProductID and you can get the product ID via this method.
  2. You should publish a method to access a group of products. That means OOJDBC needs a result set with multiple rows, and each row is one of the products, so that you should define a class that can retrieve the rows. In this example, the file SQLReader.java in demo.zip takes this role. In this file, there is a static* method JCollection execSQL(String jdbcDriver, String url, String sql), and this method returns a collection that contains the rows of the products. This collection can be one of the following three classes java.util.collection for Java2, java.util.Vector for Java1.1 and com.jinfonet.jdbc.obj.JCollection for both.

Also, the batch files used to start the Model Wizard, JReport Designer and JReport Server should be modified before you can import the product table and use it to generate reports. To do this:

  1. Save demo.zip in <install_root>\help.
  2. Add it to the class path of the batch file setenv.bat in <install_root>\bin of both Designer and Server. setenv.bat updates the class path for both ModelWizard and Designer.
Importing the class file using the Model Wizard

To import the class file using the Model Wizard, take the following steps:

  1. Start the Model Wizard (ModelWizard.bat).
  2. In the Object Source Wizard, click Add Table and the Add Table dialog will be displayed.
  3. In the ClassName field, type com.jinfonet.jdbc.demo.Products, input demo in the Table Name field, and then click the Parse button.
  4. Click Direct Access Path. In the Access Method dialog, input com.jinfonet.jdbc.demo.SQLReader in the Root Class Name field. Then click the Parse button. In the Methods box, select the method execSQL, and in the Parameters box, fill in the default values as follows:

    Param0 (the driver of the database): org.hsqldb.jdbcDriver
    Param1 (the connection URL of the database): jdbc:hsqldb:c:\JReport\Designer\Demo\db\DemoDB
    Param2 (the user name): sa
    Param3 (the password): (no value)
    Param4 (the SQL statement): select * from products

  5. Press the OK button and the table demo will now have been added.
  6. In the Object Source Wizard, select File > Save. You will then be prompted to save the ODF file. You should save it to <install_root>\lib or the directory where the catalog will be. Here we save it as demo.odf.

Note: The same ODF file cannot exist in both <install_root>\lib and the directory where the catalog is located.

Importing the ODF file into a catalog

To import the ODF file to a JReport catalog, take the following steps:

  1. Start JReport Designer.
  2. Click File > Catalog Management > New Catalog.
  3. In the Input New Catalog Name dialog, specify the catalog name, the data source name and the path. The catalog should be located in the directory where you saved the ODF file. For example, if you saved the ODF file in C:\odf, the new catalog should be created also in C:\odf.
  4. In the Catalog Browser, create a new connection with the Get JDBC Connection Information dialog as follows:
    1. Uncheck Use ODBC Data Source.
    2. Check the Driver checkbox, then enter com.jinfonet.jdbc.obj.ObjectDriver in the text field that follows.
    3. Type jdbc:jinfonet:object:@Filename in the URL text field. @Filename should be the .odf name you have saved but do not include the extension. So in the example, it should be jdbc:jinfonet:object:@demo.
    4. Click OK to set up the connection.
  5. In the Add Table dialog, select the table demo and click Add.
  6. Click Done to close the Add Table dialog.

Now, the table demo has been added into the catalog. You can use it to develop reports as required.

Note: When you publish the catalog and its reports to JReport Server, whether the ODF file is located in <install_root>\lib or in the directory where the catalog is located, it will be published to the path where the catalog is located on the server side.

Improvement of OOJDBC in this example

JReport provides an interface com.jinfonet.interfaces.query.TableFilter and a simple implementation com.jinfonet.jdbc.obj.TableFilterImpl, which can be used in this example to improve the performance of the select and WHERE clauses in a query. You can extend TableFilterImpl to create your own Reader class. In addition, a demo FilterSQLReader.java in the file demo.zip has been made for your reference.

Note: If you are using FilterSQLReader.java instead of SQLReader.java, you should input com.jinfonet.jdbc.demo.FilterSQLReader in the Root Class Name field of the Access Method dialog.