. During the learning period, I never practiced the connection pooling on Tomcat, and today I finally realized it once, playing in Tomcat and wondering if you have the same dilemma as me now. Nonsense less say directly on the code Java
public static Connection Getconnection_tomcat () { Connection conn = null; try { Context initctx = new InitialContext (); Context CTX = (context) initctx.lookup ("java:comp/env"); Object obj = (object) ctx.lookup ("Jdbc/oracledb"); Javax.sql.DataSource ds = (javax.sql.DataSource) obj; Return conn = Ds.getconnection (); } catch (Exception e) { System.out.println ("Connect error=" + e.getmessage ()); return null; } }
In Tomcat->conf->server.xml
<GlobalNamingResources> <!--Editable User database that can also is used by Userdatabaserealm to Authen Ticate users-- <resource name= "userdatabase" auth= "Container" type= " Org.apache.catalina.UserDatabase " description=" User database that can be updated and saved " factory=" Org.apache.catalina.users.MemoryUserDatabaseFactory " pathname=" Conf/tomcat-users.xml "/><!--in Tomcat Configure connection pooling- <resource name= "jdbc/oracledb" auth= "Container" type= "Javax.sql.DataSource " Driverclassname= "Oracle.jdbc.driver.OracleDriver" url= " maxactive=" " maxldle= " maxwait= "Username=" "password=" " /> </GlobalNamingResources>
In Tomcat->conf->context.xml
<Context> <WatchedResource>WEB-INF/web.xml</WatchedResource><!--Configuring a connection pool-->< ResourceLink global= "Jdbc/oracledb" name= "Jdbc/oracledb" type= "Javax.sql.DataSource"/> </Context>
That's it!
The connection pool is configured on tomcat {connect error=name [Jdbc/oracledb] is not bound in the this Context. Unable to find [JDBC]}