JNDI Datasource Tomcat Oracle
This tutorial will show you how to configure JNDI data source to tomcat server for oracle database and get connection through your program using configured JNDI name.
Before you proceed to configure JNDI Datasource Tomcat Oracle, don’t forget to copy the JDBC Driver’s jar into $CATALINA_HOME/lib.
Configuration JNDI Datasource Tomcat Oracle
Create a new test user, a new database and a single test table. Your Oracle user must have a password assigned. The driver will fail if you try to connect with an empty password.
Note: the above user should be removed once testing is complete!
Next insert some test data into the testdata table.
Context configuration for JNDI Datasource Tomcat Oracle
Define a Datasource called myoracle using the thin driver to connect as user scott, password tiger to the sid called mysid. (Note: with the thin driver this sid is not the same as the tnsname). The schema used will be the default schema for the user scott.
Use of the OCI driver should simply involve a changing thin to oci in the URL string.
web.xml configuration for JNDI Datasource Tomcat Oracle
You should ensure that you respect the element ordering defined by the DTD when you create you applications web.xml file.
Code example for JNDI Datasource Tomcat Oracle
You can use the same example application as above (asuming you create the required DB instance, tables etc.) replacing the Datasource code with something like:
Finally deploy your web app into $CATALINA_BASE/webapps either as a warfile called DBTest.war
Once deployed, you should get information form data base.