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