Define JNDI Name in Tomcat

Define JNDI name to enble database connection via tomcat configurations

You can enable connection to database using tomcat configurations. Define JNDI settings in tomcat server.xml for connecting any database type. Follow the steps below

  • Modify /conf/context.xml. Include the following JNDI names
<ResourceLink global="jdbc/{name1}" name="jdbc/{name2}" />
  • Modify /conf/server.xml. Find and add the new resource
 <Resource
auth="Container"
logAbandoned="true"
maxIdle="-1"
maxWait="10000"
removeAbandoned="true"
validationQuery="SELECT CURRENT_TIMESTAMP"
driverClassName="com.mysql.jdbc.Driver"
name="jdbc/{name1}"
password="*****" username="abc"
url="jdbc:mysql://localhost/dbaname" />
  • If your application uses Hibernate , Use the JNDI name in .cfg.xml as
<property name="connection.datasource">
java:/comp/env/jdbc/{name2}
</property>

You May Also Enjoy

Secure some web pages

Define JNDI Name in Tomcat

Web Application with Embedded Tomcat… Run as Jar

Define JNDI Name in Tomcat

TimeZone Aware Tomcat!

Define JNDI Name in Tomcat

Enable & Run Tomcat as HTTPS

Define JNDI Name in Tomcat


Dialogue & Discussion