Tomcat creates a connection pool and writes helpDB connection methods. tomcathelpdb
1. sever configuration in tomcat
<Resource auth = "Container" driverClassName = "com. microsoft. sqlserver. jdbc. SQLServerDriver"
Factory = "org. apache. tomcat. jdbc. pool. performancefactory" initialSize = "10"
JdbcInterceptors = "org. apache. tomcat. jdbc. pool. interceptor. ConnectionState;
Org. apache. tomcat. jdbc. pool. interceptor. StatementFinalizer "jmxEnabled =" true"
LogAbandoned = "true" maxActive = "100" maxWait = "10000" minEvictableIdleTimeMillis = "30000"
MinIdle = "10" name = "jdbc/myweb" password = "sa" removeAbandoned = "true"
RemoveAbandonedTimeout = "60" testOnBorrow = "true" testOnReturn = "false" testWhileIdle = "true"
TimeBetweenEvictionRunsMillis = "30000" type = "javax. SQL. DataSource"
Url = "jdbc: sqlserver: // 192.168.0.1: 4643; DatabaseName = test"
Username = "sa" validationInterval = "30000" validationQuery = "SELECT 1"/>
Put the above in this label: <GlobalNamingResources> </GlobalNamingResources>
2. configuration in context
<ResourceLink global = "jdbc/SJHIS" name = "jdbc/myweb" type = "javax. SQL. DataSource"/>
Put the above under this label: <WatchedResource> WEB-INF/web. xml </WatchedResource>
3. Create a connection calling class. The connection method in the class is as follows:
Public Connection GetConnect (){
Try {
DataSource ds = null;
Context initCtx = new InitialContext ();
Ds = (DataSource) initCtx. lookup ("java: comp/env/jdbc/myweb ");
Return ds. getConnection ();
} Catch (NamingException e ){
E. printStackTrace ();
Return null;
} Catch (SQLException e ){
E. printStackTrace ();
Return null;
}
}