Configure the connection pool in Tomcat

xiaoxiao2021-03-06  67

Configure the connection pool in Tomcat

1. Open Server.xml: Add the following connection pool parameter statement in , a complete example is as follows: factory org.apache.commons.dbcp.basicDataSourceFactory URL jdbc: Oracle: Thin: @ 172.18.51.101: 1521: sundb maxidle 20 maxactive 0 driverclassname Oracle.jdbc.driver.Orcledriver maxwait 5000 < / parameter> Removeabando NED true username CMS_User < Parameter> Logabandoned true <

/ value> removeabandonedTimeout 60 password < Value> 12345 2. Open WEB-INF / Web.xml under the project, add the following: Oracle Datasource Example JDBC / WAPORACLE javax.sql.datasource Container 3. Then write the statement of the connection database: package util;

Import java.sql. *; import javax.sql. *; import javax.naming. *;

Public class oracledb {string URL_ = "192.168.1.41:1521:Gxcring"; // String URL_ = "172.18.51.101:1521:Sundb"; string id_ = "cms_user"; string pass_ = "12345";

CONNECTION conn = null; statement stmt = null;

Public OracleDb () {Try {//class.forname ("Oracle.jdbc.driver.Oracledriver"); // conn = drivermanager.getConnection ("JDBC: Oracle: Thin: @" URL_, ID_, Pass_); context INITCONText (); context envcontext = (context) INITCONTEXT.LOOKUP ("java: / comp / ENV"); DataSource DS = (DataSource) EnvContext.lookup ("JDBC / Waporacle"); // Note The name here The same is the same as the name in the configuration file. CONN = ds.getConnection ();

stmt = conn.createStatement (ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);} catch (NamingException ne) {System.out.println ( "Initial DataSource error."); ne.printStackTrace ();} catch (SQLException e) {System .out.println ("Oracle:" E); E.PrintStackTrace ();}} / ** * Return Connction Object * @Param None * @return CONNCTION * / PUBLIC Connection getConn () {Return this.conn;} }

Ha ha. This will be, there is nothing to use to use JDBC when calling the database elsewhere. Very simple.

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

New Post(0)