Deploying a BIRT Report to an Application Server : Using connection pooling on Tomcat : Configuring a JNDI connection object on Tomcat
 
Configuring a JNDI connection object on Tomcat
The JNDI URL property for the JDBC data source supports retrieving a JDBC connection from a pool when BIRT reports are deployed to a web application server. More information about configuring connection pooling on Tomcat is available at:
http://tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.html
How to configure a JNDI connection object on Tomcat
The following example assumes you already have deployed the BIRT report viewer to a Tomcat 6.0 application server in the folder, $TOMCAT_INSTALL
/webapps/birt, as described earlier in this chapter.
1 Install the JDBC Driver. Make an appropriate JDBC driver available to both Tomcat internal classes and the web application, for example, by installing the driver's JAR files into the following library directory in the Tomcat application server home folder:
$CATALINA_HOME/common/lib
2 Declare the resource requirements in the BIRT report viewer’s
WEB-INF/web.xml file. For example, add the following entry to set up a JNDI service for a MySQL format database with the name, MySqlDB:
<resource-ref>
<description>Resource reference to a factory for
java.sql.Connection</description>
<res-ref-name>jdbc/MySqlDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
3 Configure Tomcat's resource factory as a Resource element in the BIRT report viewer’s META-INF/context.xml file, similar to the following lines:
<Context>
<Resource name="jdbc/MySqlDB" auth="Container"
type="javax.sql.DataSource" maxActive="5" maxIdle="-1"
maxWait="10000" username="root" password=""
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/classicmodels"
description="MySQL DB"/>
</Context>
4 Make the JNDI URL in your report design match Tomcat’s resource factory, similar to the following line:
java:comp/env/jdbc/MySqlDB
5 Open the report design using BIRT Report Designer. Edit the data source. In Edit Data Source, in JNDI URL, type the URL, as shown in Figure 2‑3.
Figure 2‑3 Setting the JNDI URL for a JDBC data source
6 Copy the report design to the BIRT report viewer root folder.
7 Restart the Tomcat service.
8 Run the report using a URL similar to the following one:
http://localhost:8080/birt/run?__report=myJNDIReport.rptdesign
The report uses a connection from the connection pool to connect to the database on a MySQL server.