Tomcat creates a connection pool and writes helpDB connection methods. tomcathelpdb

Source: Internet
Author: User

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;
}
}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.