Index

Using Another Connection as a Substitute of Catalog Connection

Normally, after a report has been created, it is fixed to a specific catalog connection. With the J2EE data source support feature, you can change to another runtime JDBC or JNDI data source to run reports.

This allows you to control the catalog data source connections on JReport Enterprise Server to connect dynamically to your production data sources.

Configure the datasource.xml file

In order to enable you to conveniently set different connections in JReport Server, a configuration file, datasource.xml, is provided with which you can define the connection to use at run-time by setting up connection mapping information such as the JDBC driver, URL, or JNDI data source name, user and password, depending on the data source your application uses.

The datasource.xml file is located in the <install_root>\bin directory. Change this file according to the data source you want to use. Two types of connections are supported by JReport Server, they are JNDI data source connection and JDBC connection.

The content of the datasource.xml file is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<datasource-mapping>
     <datasource>
               <catalog-connection-name>Connection1</catalog-connection-name>
               <connection-type>JNDI</connection-type>
               <jndi-datasource>Sample</jndi-datasource>
     </datasource>
     <datasource>
               <catalog-connection-name>Connection2</catalog-connection-name>
               <connection-type>JDBC</connection-type>
               <driver>sun.jdbc.odbc.JdbcOdbcDriver</driver>
               <url>jdbc:odbc:jinfonet</url>
               <user>Username</user>
               <password>Password</password>
     </datasource>
</datasource-mapping>

Element Descriptions:

Notes:

Username and Password Encryption

Once the user and password are provided in the datasource.xml file, they will be encrypted into one line, which will be like the following:

<encrypt-sign>enDkq7srM9cHhoUwzYXJ3NvcDIYk</encrypt-sign>

If you want to change the user name and password information, just remove this line and type the new information again.

After this, you can integrate JReport Server with your application server.

If you are using a self-contained war file, make sure the datasource.xml file is included in the war file, before making the self-contained war file, please modify %InstallRoot%/bin/makewar.xml, and add <include name="datasource.xml" /> into <zipfileset dir="${installroot}/bin" prefix="workspace/bin"> section. Before you deploy it to web server, make sure the datasource.xml is included in the "jreport.war/WEB-INF/lib/jrenv.jar/workspace/bin/datasource.xml".

Reference Note: For more detailed instructions on making self-contained war files, see Deploying JReport Enterprise Server as a Self-Contained WAR/EAR.

If you are integrating JReport server to an application using a normal war file, usually you need to specify -Dreporthome parameter in the application server so that the application server can locate and load the resources it needs. Since the datasource.xml is already in the bin directory, you don't need to do anything special for this file.

The Connection Priority

If you are using a catalog connection, datasource.xml, and at the same time, you have set new connection information via the server API/URL ((jrs.jdbc_driver, jrs.jdbc_url, jrs.db_user, jrs.db_pswd), the priority of these three are to like this:

Server API > datasource.xml > catalog connection

This means that if the approach with higher priority fails to get the connection, the one with lower priority will be used.

Reloading datasource.xml

After you have made changes to the datasource.xml file, you need to reload it in JReport Server. This file can be reloaded in the following ways:

Case: Using JNDI data source connections of WebLogic Server

Taking WebLogic as an example, use the following steps:

  1. Start WebLogic server, navigate to <YourProjectName> | Services | JDBC | Connection Pools. On the configuration tab, make sure the connection you are going to use is there and correctly set up.
  2. Browse to  <YourProjectName> | Services | JDBC | Data Sources. On the Configuration tab, create a data source using the JNDI name MyJNDISample. Select the correct connection from the Pool Name drop-down list.
  3. Open <install_root>\bin\datasource.xml and add:

    <datasource-mapping>
         <datasource>
                   <catalog-connection-name>default</catalog-connection-name>
                   <connection-type>JNDI</connection-type>
                   <jndi-datasource>MyJNDISample</jndi-datasource>
                   <user>youruserid</user>
                   <password>yourpassword</password>
         </datasource>
    </datasource-mapping>
  4. Integrate JReport Server to WebLogic.
  5. Run the report that is using this connection.

Case 2: Using JNDI data source connections of JBoss server

Taking JBoss as an example, in this case, DB2 is used, and suppose JBoss is installed under D:\jboss-4.0.1, use the following steps:

  1. Copy the DB2 driver to D:\jboss-4.0.1\server\default\lib.
  2. Create the file db2-ds.xml in D:\jboss-4.0.1\server\default\deploy and add the following content:

    <?xml version="1.0" encoding="UTF-8"?>

    <datasources>
         <local-tx-datasource>
                   <jndi-name>DB2DataSource</jndi-name>
                   <connection-url>jdbc:db2://dbs-b/sample</connection-url>
                   <driver-class>COM.ibm.db2.jdbc.net.DB2Driver</driver-class>
                   <user-name>db2admin</user-name>
                   <password>db2admin</password>
                   <min-pool-size>0</min-pool-size>
                   <metadata>
                             <type-mapping>DB2</type-mapping>
                   </metadata>
         </local-tx-datasource>
    </datasources>
  3. Modify datasource.xml (<install_root>\bin), make sure the followings are included:

    <datasource-mapping>
         <datasource>
                   <catalog-connection-name>default</catalog-connection-name>
                   <connection-type>JNDI</connection-type>
                   <jndi-datasource>java:/DB2DataSource</jndi-datasource>
         </datasource>
    </datasource-mapping>
  4. Build the self-contained war file using makewar.bat (<install_root>\bin).
  5. Integrate JReport server to JBoss.
  6. Run the report that is using this connection.

Index