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 host> room: < ! - USE JNDI to CONECTION -> username name> admin value> parameter> password name> lxc value> parameter> driverclassname name> com.ibm.db2.jcc.db2driver value> Parameter> URL name> jdbc: db2: // localhost: 5000 / testdb value> parameter> maxactive name> 100 value> parameter>
MaxIdle name> 30 value> parameter> maxwait name> 10000 < / value> parameter> removeabandoned name> true value> parameter> removeAbandonedTimeout name> <-! Use the removeAbandonedTimeout parameter to set the number of seconds a DB connection has been idle before it is considered abandoned -.> 60 value> parameter> ResourceParams> Context> 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 web-app>.
ConnectDB test description> JDBC / DB2SQL res-ref-name> javax.sql .Datasource res-type> Container res-auth> resource-ref> 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: XML Version = "1.0" Encoding = "UTF-8"?> JDBC / DB2SQL jdi-name> jdbc: db2: // localhost: 5000 / testdb Connection-URL> com.ibm.db2.jcc.db2driver driver-class> admin user-name> lxc password> 20 min-pool-size> 50 max-pool-size> 0 idle-timeout-minutes> local-tx-dataroup> datasources> 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");