Sunday, April 20, 2014

How to add JNDI data source in Pentaho BI 5.0.1

Until Pentaho BI version 4.8 CE there was an option to add JNDI (Java Naming and Directory Interface) as a data source. But, in the newer version of Pentaho BI 5.0.1 CE version it was taken out. So, the simple-jndi will not work anymore on new version of Pentaho BI 5.0.1 CE.

Still we can use JNDI connection to the database. For this you need to create the data source in Tomcat server itself which will be active through out life cycle of Pentaho BI.

The Steps to perform this is given below:

(Please note that the example given below is used to configure JNDI for MySQL database)

1. First, Stop the tomcat server (Pentaho BI Server) running
2. Edit the file tomcat/webapps/pentaho/WEB-INF/web.xml
3. Insert the code snippet given below just after this line

<!-- insert additional resource-refs -->

<resource-ref>
    <description>DataSourceName</description>
    <res-ref-name>jdbc/myDataSource</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>

4. Save the file and exit.
5. Now, edit another file in tomcat/conf/context.xml 
6. Anywhere inside of the  element, add the XML snippet shown below:
    <Resource name="jdbc/myDataSource"
    auth="Container" type="javax.sql.DataSource"
    factory="org.apache.commons.dbcp.BasicDataSourceFactory" 
    maxActive="20" 
    maxIdle="5"
    maxWait="10000" 
    username="dbuser" 
    password="password" 
    driverClassName="com.mysql.jdbc.Driver"
    url="jdbc:mysql://localhost:3306/DataSourceName"
    />

7. Save the file and exit.
8. Start the Pentaho BI Server and the new JNDI connection should be available

No comments: