Database connection pool in Server.xml

xiaoxiao2021-03-06  107

Generally set in server.xml, but the program also wants to call the name of the connection pool to find the database.

Take the server.xml in Tomcat as an example:

Configure the connection pool

??

??

??

Factory

Org.apache.commons.dbcp.basicDataSourceFactory

??

Driverclassname

Oracle.jdbc.driver.Oracledriver

??

URL

JDBC: Oracle: Thin: @ 192.168.3.16: 1521: Cucu

??

Username

WNJC

??

Password

WNJC

??

Maxactive

20

??

MaxIdle

10

??

Maxwait

10,000

??

??

Configure as follows in web.xml:

"- // Sun Microsystems, Inc.//dtd Web Application 2.3 // En"

"

http://java.sun.com/dtd/web-app_2_3.dtd ">

CMS V1.0

?

DB Connection

JDBC / WNJC

Javax.sql.datasource

Container

The program call is as follows:

Public static synchronized connection pubgetcon () throws sqlexception {

?? Try {

??? context jndicntx = new initialContext ();

????? DataSource DS =

??????????? ("java: comp / env / jdbc / wnjc");

??? Return DS.GetConnection ();

??} catch (namingexception ne) {

??? throw new ejbexception (ne);

??}

?

// WNJC is the name of the connection pool

转载请注明原文地址:https://www.9cbs.com/read-125941.html

New Post(0)