JNDI Example

Here is an example of using a JNDI data source. This example is for Tomcat. Other containers (such as Jetty) use different methods to define JNDI data sources, but once it is defined, Live API Creator's behavior should be the same.

Step 1: Define the JNDI data source

In Tomcat's server.xml file, define the following in the GlobalNamingResources section. This example is for a Derby database, other database types will look different:

<Resource accessToUnderlyingConnectionAllowed="true" auth="Container" defaultAutoCommit="false" driverClassName="org.apache.derby.jdbc.EmbeddedDriver" initialSize="10" logAbandoned="true" maxIdle="0" maxTotal="500" maxWaitMillis="15000" minIdle="0" name="jdbc/MyDB" removeAbandonedOnMaintenance="true" removeAbandonedTimeout="30" timeBetweenEvictionRunsMillis="30000" type="javax.sql.DataSource" url="jdbc:derby:/tmp/MyDB;create=true" username="MyDB"/>

Please note that creating this in the GlobalNamingResources section is not necessarily the best thing to do, but it is the easiest. Consult Tomcat's documentation for further details.

Step 2: Define the JNDI reference

In Tomcat's context.xml file, define the following in the Context section:

<ResourceLink global="jdbc/MyDB" name="jdbc/MyDB" type="javax.sql.DataSource"/>

Step 3: Use the JNDI data source from Live API Creator

For instance, in API Creator, create a new API, select the JNDI Data Source option, and specify MyDB as the JNDI data source name.