Configure database connection pool

Source: Internet
Author: User

Not long ago, I saw an article on configuring the database connection pool in Tomcat on the blog of l_xiaodao. I tried to configure the database twice as described in the following comparison: I tried sqlserver database once, the other is the Oracle database. The configuration process is described as follows:

My tomcat version is 5.0.25. First create a directory D:/test in disk D, then create the WEB-INF directory under test, create the classes directory and lib directory under the WEB-INF directory, copy a copy of the web under the existing web application directory. remove unnecessary content from the XML file. Create a test. xml file under <catalina_home>/CONF/Catalina/localhost. the specific content of the file is as follows:

<? XML version = '1. 0' encoding = 'utf-8'?>
<Context crosscontext = "true" DEBUG = "5" docbase = "D:/test" Path = "/test" reloadable = "true">
<Resource Name = "JDBC/zhukai" type = "javax. SQL. datasource"/>
<Resourceparams name = "JDBC/zhukai">
<Parameter>
<Name> URL </Name>
<Value> JDBC: oracle: thin: @ 192.168.10.120: 1521: ora32 </value>
</Parameter>

<Parameter>
<Name> maxidle </Name>
<Value> 30 </value>
</Parameter>
<Parameter>
<Name> maxactive </Name>
<Value> 10 </value>
</Parameter>
<Parameter>
<Name> driverclassname </Name>
<Value> oracle. JDBC. Driver. oracledriver </value>
</Parameter>
<Parameter>
<Name> maxwait </Name>
<Value> 10000 </value>
</Parameter>

<Parameter>
<Name> username </Name>
<Value> tjpt </value>
</Parameter>
<Parameter>
<Name> password </Name>
<Value> tjpt </value>
</Parameter>
</Resourceparams>
</Context>

Then write a test index. jsp file (refer to the blog from l_xiaodao ):

<% @ Page contenttype = "text/html; charset = gb2312" Language = "Java" Import = "Java. SQL. *" errorpage = "" %>
<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<% @ Page import = "javax. SQL. *" %>
<% @ Page import = "javax. Naming. *" %>

<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> î þ ± ê ì â î äµ</title>
</Head>

<Body>
<%
Try {
Initialcontext cxt = new initialcontext ();
Out. Print ("first success ");

Datasource DS = (datasource) cxt. Lookup ("Java: COMP/ENV/jdbc/zhukai ");
Out. Print ("second success ");

Connection conn = Ds. getconnection ();
Out. Print ("third success ");
Statement stmt = conn. createstatement ();
String SQL = "select count (*) from xt_corpusers ";
Resultset rs1_stmt.exe cutequery (SQL );
While (Rs. Next ()){
Out. println (Rs. getstring (1 ));
}
}
Catch (exception e) {// out. println ("there is exception" + E. getmessage ());
E. printstacktrace ();
}

%>
</Body>
</Html>

Restart Tomcat and open IE and enter http: // localhost: 8080/test to check whether the database configuration is successful.

Note: Normally, I fail to succeed. This error often occurs: cannot create JDBC driver of class ''for connect URL 'null'. I checked a lot of information online, I also attended some foreign forums and found that many of my colleagues had such problems. Some people suggest copying web. XML to the META-INF directory, but to change the name, the content is the same. However, according to replies from many people, there was almost no error in the original configuration file. After I came back from dinner, I took the test. it's strange that XM is deleted and re-written.

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.