How to Add a New JNDI Connection in Tomcat

Procedure


To add a JNDI connection to a MySQL DB in Tomcat application server for TIBCO JasperReports® Server web application to use, please do the following:

Table of Contents 
  1. Add a resource entry to JasperReports Server Context configuration file ( \jasperserver-pro\META-INF\context.xml ). For example:

    <Resource name="jdbc/mysqldbname"
              auth="Container"
              type="javax.sql.DataSource"
              maxActive="100"
              maxIdle="30"
              maxWait="10000"
              username="jasperdb"
              password="password"
              driverClassName="com.mysql.jdbc.Driver"
              validationQuery="select 1"
              testOnBorrow="true"
              url="jdbc:mysql://127.0.0.1:3306/<database_name>?useUnicode=true&amp;characterEncoding=UTF-8&amp;autoReconnect=true&amp;autoReconnectForPools=true" />

    The driver class name above is for the standard MySQL Driver. JasperReports Server v5.5 now ships with the Mariadb client, "org.mariadb.jdbc.Driver".

  2. Add a reference in JasperReports Server web configuration (\jasperserver-pro\WEB-INF\web.xml file) to the newly created JNDI entry to make it available to the web application:

    <resource-ref>
        <description>MySQL JasperServer repository</description>
        <res-ref-name>jdbc/mysqldbname</res-ref-name>
        <res-type>javax.sql.ConnectionPoolDataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>
  3. Put the JDBC driver referenced in the connection into the apache-tomcat\lib directory

  4. Clean up apache-tomcat\conf\Catalina\localhost directory (see JNDI datasource update trouble: Cannot create JDBC driver of class '' for connect URL 'null' for details)

  5. Restart the server

  6. Log in to JasperReports Server through the web UI and add/test JNDI connection using "jdbc/mysqldbname" as the resource

After upgrading to Tomcat 8 JNDI connection should be updated. Please refer to following article for more info:

http://stackoverflow.com/questions/22518748/classnotfoundexception-when-upgraded-to-tomcat-8


References



TTC-20130720

Feedback
randomness