Configure database connection pool

xiaoxiao2021-03-06  92

Configuring the Tomcat connection pool: 1: Java Run Environment 2: Database Server 3: JAR Pack of JDBC to $ Catalina_Home / Common / LIB: If it is SQL Server, contain 3 JAR Packages: Msbase.jar, MSSQLServer.jar, Msutil .jar; if it is a DB2 database: contains db2jcc.jar, db2jcc_license_cu.jar4: Set the connection pool at $ catalina_home / conf / server.xml: The following is the code: you must put it in and room: < ! - USE JNDI to CONECTION -> username admin password lxc driverclassname com.ibm.db2.jcc.db2driver URL jdbc: db2: // localhost: 5000 / testdb maxactive 100

MaxIdle 30 maxwait 10000 < / value> removeabandoned true removeAbandonedTimeout <-! Use the removeAbandonedTimeout parameter to set the number of seconds a DB connection has been idle before it is considered abandoned -.> 60 5: Setting the referenced resource in $ catalina_home / webapps / Quality / Web-INF / Web.xml: The following is the configuration code, must be placed in and .

ConnectDB test JDBC / DB2SQL javax.sql .Datasource Container 6: Connect the database through JAVA files through JNDI Name, simple Writing is as follows: import javax.naming.context; import javax.naming.initialcontext; import javax.sql.datasource; .......................... ..... private connection conn = null; private context ctx = null; ............................... ..... try {ctx = new initialcontext (); if (ctx == null) throw new exception ("There is no matching environment"); DataSource DS = (Datasource) CTX.lookup ("Java: Comp / ENV / JDBC / DB2SQL "); if (ds == null) throw new exception (" no matching database "); this.conn = ds.getConnection (); // Get a connection} catch (Exception E) {System.out. Println ("Can 'T Link Database!" E);

Similarly, the way to configure the connection pool under JBoss is as follows: 1: Add a file under D: / JBoss / Server / Default / Deploy: DB2SQL-DS.XML: Writing is as follows: JDBC / DB2SQL jdbc: db2: // localhost: 5000 / testdb com.ibm.db2.jcc.db2driver admin lxc 20 50 0 2: Add JAR package for JDBC connections under the web-inf / lib directory in the ××. War project package you applies: For example, DB2 is: db2jcc.jar, db2jcc_license_cu.jar; 3: The difference is that when Java calls JNDI Name, the Writing is: ctx = new initialcontext (); if (ctx == null) throw new exception ("no Matching environment "); / ** Note: Looking for different writing methods of JNDI Name * / DataSource DS = (DataSource) CTX.lookup (" Java: / JDBC / DB2SQL "); if (ds == null) Throw new Exception "No matching database");

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

New Post(0)