Use Data Link buffer pool in tomcat5.0.27

Source: Internet
Author: User

1. Place the corresponding JDBC package in the common/lib directory of the tomcat installation directory.
Ii. tomcat configuration file content (Taking ORACLE and thin connection as an example)
<? XML version = '1. 0' encoding = 'utf-8'?>
<Context docbase = "E:/workspace/toshba" Path = "/toshba" reloadable = "true" workdir = "E: \ workspace \ toshba \ work">
<Resource Name = "JDBC/oracledb" auth = "Container" type = "javax. SQL. datasource"/>

<Resourceparams name = "JDBC/oracledb">

<Parameter>
<Name> factory </Name>
<Value> org. Apache. commons. DBCP. basicperformancefactory </value>
</Parameter>

<Parameter>
<Name> driverclassname </Name>
<Value> oracle. JDBC. Driver. oracledriver </value>
</Parameter>

<Parameter>
<Name> URL </Name>
<Value> JDBC: oracle: thin: @ UFJ: 1521: drch1001 </value>
</Parameter>

<Parameter>
<Name> username </Name>
<Value> Scott </value>
</Parameter>

<Parameter>
<Name> password </Name>
<Value> tiger </value>
</Parameter>

<Parameter>
<Name> maxactive </Name>
<Value> 20 </value>
</Parameter>

<Parameter>
<Name> maxidle </Name>
<Value> 10 </value>
</Parameter>

<Parameter>
<Name> maxwait </Name>
<Value>-1 </value>
</Parameter>

</Resourceparams>
</Context>

Iii. Web. XML file content
<? XML version = "1.0" encoding = "UTF-8"?>
<! Doctype web-app public "-// Sun Microsystems, Inc. // DTD web application 2.3 //" http://java.sun.com/dtd/web-app_2_3.dtd ">
<Web-app>
<Resource-ref>
<Description> Oracle datasource example </description>
<Res-ref-Name> JDBC/oracledb </RES-ref-Name>
<Res-type> javax. SQL. datasource </RES-type>
<Res-auth> container </RES-auth>
</Resource-ref>
</Web-app>

4. JavaCodeWrite

Package com. CSK. DM;

Import java. util. collections;
Import java. util. hashmap;
Import java. util. Map;

Import javax. Naming. context;
Import javax. Naming. initialcontext;
Import javax. Naming. namingexception;
Import javax. SQL. datasource;

Public class servicelocator {
Private initialcontext Ic = NULL;
Private map cache;
 
Private Static servicelocator me = NULL;
 
Static {
Try {
Me = new servicelocator ();
} Catch (servicelocatorexception SE ){
System. Err. println (SE );
Se. printstacktrace (system. Err );
}
}

/**
*
*/
Public servicelocator () throws servicelocatorexception {
Try {
Ic = new initialcontext ();
Cache = collections. synchronizedmap (New hashmap ());
} Catch (namingexception ne ){
Throw new servicelocatorexception (NE );
} Catch (exception e ){
Throw new servicelocatorexception (E );
}
}

/**
* @ Return
*/
Public static servicelocator getinstance (){
Return me;
}

/**
* @ Param datasourcename
* @ Return
* @ Throws servicelocatorexception
*/
Public datasource getdatasource (string datasourcename) throws servicelocatorexception {
Datasource = NULL;
Try {
If (Cache. containskey (CENAME )){
Datasource = (datasource) cache. Get (datasourcename );
} Else {
Context CTX = (context) IC. Lookup ("Java: COMP/ENV ");
Datasource = (datasource) CTX. Lookup (datasourcename );
Cache. Put (datasourcename, datasource );
}
} Catch (namingexception ne ){
Throw new servicelocatorexception (NE );
} Catch (exception e ){
Throw new servicelocatorexception (E );
}
Return datasource;
}

}

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.