Tomcat data source configuration

Source: Internet
Author: User
Two methods: 1. Tomcat server configuration: 1. Set & lt; Resourcename & quot; jdbc/TestDB & quot; auth & quot; Container & quot; type & quot; javax. SQL. dataSource & quot; maxActive & quot; 100 & quot; maxIdl

Two methods:
I. Tomcat server configuration:
1.

MaxActive = "100" maxIdle = "30" maxWait = "10000"

Username = "root" password = "sa" driverClassName = "com. mysql. jdbc. Driver"

Url = "jdbc: mysql: // localhost: 3306/employee_manager? AutoReconnect = true "/>

Paste it to the Tomcat 6.0/conf context. xml file

2.

DB Connection

Jdbc/TestDB

Javax. SQL. DataSource

Container

Paste it to the web. xml file

3. Place the database driver file in Tomcat 6.0/lib.

4. application in the program:

Public static Connection getConnection (){

DataSource ds;

InitialContext cxt;

Try {

Cxt = new InitialContext ();

Ds = (DataSource) cxt. lookup ("java:/comp/env/jdbc/TestDB ");

Con = ds. getConnection ();

} Catch (Exception e ){

E. printStackTrace ();

}

SqlServer2005 is the same as the preceding steps:

Url = "jdbc: microsoft: sqlserver: // 127.0.0.1: 1433; DatabaseName = employee_manager"

? AutoReconnect = true should be deleted!

Oracle:

Name = "jdbc/ums"
Type = "javax. SQL. DataSource"
Username = "neu"
Password = "oracle"
Url = "jdbc: oracle: thin: 127.0.0.1: 1521: ORACLE"
DriverClassName = "oracle. jdbc. driver. OracleDriver"
MaxIdle = "2"
MaxWait = "5000"
MaxActive = "4"/>
WEB-INF/web. xml

Skip step 1

Applicable to all tomcat projects
2. configure in the project:
1. create a context. xml file in the WebRoot/META-INF with the following content:


Auth = "Container"
Type = "javax. SQL. DataSource"
DriverClassName = "oracle. jdbc. driver. OracleDriver"
Url = "jdbc: oracle: thin: @ 127.0.0.1: 1521: orcl"
Username = "scott"
Password = "tiger"
MaxActive = "100"
MaxIdle = "30"
MaxWait = "10000" type = "codeph" text = "/codeph"/>

2. use the following code:
Try {
InitialContext initContext = new InitialContext ();
Context context = (Context) initContext. lookup ("java: comp/env ");
DataSource ds = (DataSource) context. lookup ("jdbc/ORACLE ");

Conn = ds. getConnection ();
System. out. println ("connect to the database through the connection pool. ");
} Catch (Exception e ){
Throw new ServletException (e );

 

Related Article

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.