Jndi configuration: This configuration requires that the data source be configured in the Server.xml and context.xml of Tomcat and referenced in the project.
We need to add the jar package of the database connection under Tomcat, the download address of the related package is shown below (ojdbc14;c3p0 data source):
http://download.csdn.net/detail/qq_35624642/9778118
The first step was to find the Globalnamingresources node in Tomcat's Server.xml and add a global data source under the node, where I added two data sources.
<!--Global JNDI Resources
Documentation at/docs/jndi-resources-howto.html
-->
<GlobalNamingResources>
<!--Editable User database that can also is used by
Userdatabaserealm to authenticate users
-->
<resource name= "Userdatabase" auth= "Container"
Type= "Org.apache.catalina.UserDatabase"
description= "User database" can be updated and saved "
factory= "Org.apache.catalina.users.MemoryUserDatabaseFactory"
Pathname= "Conf/tomcat-users.xml"/>
<resource name= "Userdatabase" auth= "Container"
Type= "Org.apache.catalina.UserDatabase"
description= "User database" can be updated and saved "
factory= "Org.apache.catalina.users.MemoryUserDatabaseFactory"
Pathname= "Conf/tomcat-users.xml"/>
<resource auth= "Container"
description= "DB Connection"
Driverclass= "Oracle.jdbc.driver.OracleDriver"
Maxpoolsize= "20"
Minpoolsize= "5"
Acquireincrement= "5"
Maxidletime= "300"
Idleconnectiontestperiod= "60"
Automatictesttable= "Test"
acquireretryattempts= "30"
Breakafteracquirefailure= "true"
Name= "Jdbc/amodmondbsource"
User= "Amod"
Password= "AMODDB"
factory= "Org.apache.naming.factory.BeanFactory"
Type= "Com.mchange.v2.c3p0.ComboPooledDataSource"
Jdbcurl= "Jdbc:oracle:thin:@10.111.0.108:1521:orcl"/>
<resource auth= "Container"
description= "DB Connection"
Driverclass= "Oracle.jdbc.driver.OracleDriver"
Maxpoolsize= "20"
Minpoolsize= "5"
Acquireincrement= "5"
Maxidletime= "300"
Idleconnectiontestperiod= "60"
Automatictesttable= "Test"
acquireretryattempts= "30"
Breakafteracquirefailure= "true"
Name= "Jdbc/ddamodmondbsource"
User= "Ddamod"
Password= "DDAMODDB"
factory= "Org.apache.naming.factory.BeanFactory"
Type= "Com.mchange.v2.c3p0.ComboPooledDataSource"
Jdbcurl= "Jdbc:oracle:thin:@10.111.0.108:1521:orcl"/>
</GlobalNamingResources>
The second step is to find the context.xml of Tomcat, and add a ResourceLink node under the context node to reference the data source configured in the first step
<!--the contents of this file is loaded for each Web application-->
<Context>
<!--Default set of monitored resources. If One of these changes, the-->
<!--Web application'll be reloaded. -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
<!--uncomment this to disable session persistence across Tomcat restarts-->
<!--
<manager pathname= ""/>
-->
<resourcelink name= "Jdbc/amodmondbsource" global= "Jdbc/amodmondbsource" type= "Javax.sql.DataSource"/>
<resourcelink name= "Jdbc/ddamodmondbsource" global= "Jdbc/ddamodmondbsource" type= "Javax.sql.DataSource"/>
</Context>
The third step is to refer to the configured data source in the project
Amoddb.jndi.name=java\:comp/env/jdbc/amodmondbsource
Ddamoddb.jndi.name=java\:comp/env/jdbc/ddamodmondbsource
Root.jndi.name=java\:comp/env/jdbc/amodmondbsource
Null.jndi.name=java\:comp/env/jdbc/datasourcedb