##### Example 1: EJB deployed to Java EE

This example shows how to use an EJB deployed to Java EE as a data source and import it to a JReport catalog via OOJDBC.

Follow the steps below to achieve your goal:

1. Installation
2. Importing the EJB using the Model Wizard
3. Importing the ODF file into a catalog

##### Installation

You are required to install the following before you can import EJB using the Model Wizard:

1. Install Java EE. You can download it from http://java.sun.com/javaee/downloads/index.jsp. After the installation of Java EE, you will find j2ee.jar in `<java_ee_install_root>\lib`.
2. Install Jaxp1.1. You can download it from http://java.sun.com/xml/download.html. After installation, you will find three jars xalan.jar, crimson.jar and jaxp.jar in `<jaxp1.1_insatll_root>`.
3. Install JReport Designer, then add the four jars into the ADDCLASSPATH variable of the batch file setenv.bat in `<designer_install_root>\bin`. For example:

   `set ADDCLASSPATH=%JAVAHOME%\lib\tools.jar;c:\java\classes;c:\jaxp1.1\xalan.jar;c:\jaxp1.1\crimson.jar;c:\jaxp1.1\jaxp.jar;`

Note: After you have deployed your EJB to the Java EE server, a Jar will be returned in the root directory. In this example, Java(TM) Pet Store Demo of jps1.0 in Java EE has been used. Note that versions later than jps1.0 are not supported. After deploying to the Java EE server, estoreClient.jar is returned to the root directory. Add it to the class path too. For example:

`set ADDCLASSPATH=%JAVAHOME%\lib\tools.jar;c:\jps1.0\estoreClient.jar;c:\jaxp1.1\xalan.jar;c:\jaxp1.1\crimson.jar;c:\jaxp1.1\jaxp.jar;`

##### Importing the EJB using the Model Wizard

Make an EJB initializing class that is coded by Jinfonet, and is for looking up EJBHome by the JNDI name.

This example uses Java(TM) Pet Store Demo. JNDI name is estore/catalog. The class name is com.sun.estore.catalog.model.Category. This table is defined by users. Users can get the table they request through parsing the class.

1. Run the modified batch file ModerWizard.bat in `<designer_install_root>\bin` and the Object Source Wizard will then be displayed. Click Add Table.
2. In the Add Table dialog, enter com.sun.estore.catalog.model.Category in the ClassName field and define the table name as Category. Then click the Parse button.
3. Click the Direct Access Path button to define the accessing path in the Access Method dialog.
   1. Fill in com.jinfonet.jdbc.ejb.EJBInitializer in the Root Class Name field. Then click the Parse button.
   2. In the Parameter box, find the DefaultValue column and fill in estore/catalog by which the EJB in the Java EE server will be accessed. Check the CastTo option, and enter com.sun.estore.catalog.ejb.CatalogHome.

      Note: After you enter the DefaultValue, you should press Enter on your keyboard, or an error will occur. When you set cast to, you should also start the Java EE server by running j2ee.bat in `<java_ee_install_root>`. And you should also choose first.

   3. If you want to use a dynamic parameter, check the option Is Dynamic. The syntax of the method is: an array of Boolean values to indicate which parameter is dynamic at runtime. If the parameter is dynamic the value should be prompted and initialized before the SQL is executed.
   4. Click Next. In the next dialog, choose create as the method name.
   5. Click Next, and now you can see the return type of the method name getCategories defined previously.
   6. Click OK and the table Category will now have been added.
4. In the Object Source Wizard, select File > Save. You will then be prompted to save the ODF file. You should save it to `<designer_install_root>\lib` or the directory where the catalog will be. Here we save it as ejb.odf.

Notes:

- If specifying to apply dynamic parameters, that is, you check the option Is Dynamic, the parameter will be passed to JReport Designer. After you create a connection in the Catalog Browser, you will find the parameter in the Parameters node.
- The same ODF file cannot exist in `both <designer_install_root>\lib` and the directory where the catalog is located.

##### Importing the ODF file into a catalog

To import the ODF file that is generated when you imported the EJB using the Model Wizard, take the following steps:

1. Start JReport Designer with the modified batch file.

   Note: Before you start creating reports, you should first start your database. In this example, start cloudscape in `<j2sdkee1.2_install_root>`.

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. Enter com.jinfonet.jdbc.obj.ObjectDriver in the Driver text field.
   2. Type jdbc:jinfonet:object:@Filename in the URL text field. @Filename should be the .odf name you have saved. So in the example, it should be jdbc:jinfonet:object:@ejb.
   3. Click OK.
5. In the Add Tables dialog, select the two tables in the Tables box, and click the Add button.

Now, the tables will have been added into the catalog. You can use it to develop reports as required.