tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Malcolm Green <Malcolm.Gr...@kcom.com>
Subject RE: Connection Pooling
Date Tue, 25 Feb 2003 10:35:54 GMT
I have DBCP connection pooling working as follows using Tomcat 4.1.12:

Under the <Context> element for your application (this can either be in the
server.xml file or a separate xml file in the webapps dir)  I have the
following config:

 	      <Resource name="jdbc/XXXX" scope="Shareable"
type="javax.sql.DataSource"/>

	      <ResourceParams name="jdbc/XXXX">
      		<parameter>
		      	<name>factory</name>
	
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
		      </parameter>

		      <parameter>
				<name>maxActive</name>
				<value>100</value>
			</parameter>

		      <parameter>
				<name>maxIdle</name>
				<value>30000</value>
			</parameter>

		      <parameter>
				<name>maxWait</name>
				<value>100</value>
			</parameter>
        
		      <parameter>
				<name>username</name>
				<value>theUser</value>
			</parameter>
		
		      <parameter>
				<name>password</name>
				<value>thePassword</value>
			</parameter>
                  
		     <parameter>
			      <name>driverClassName</name>
	
<value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
		     </parameter>
            
		    <parameter>
		      <name>url</name>
	
<value>jdbc:microsoft:sqlserver://hostname:port;databasename=myDB</value>
		    </parameter>

		    <parameter>
		      <name>validationQuery</name>
		      <value>select getdate()</value>
		    </parameter>

	  </ResourceParams>

This is an MS SQL Server config, but to change the db just make sure that
the requried JDBC jar file is in the common/lib directory and then change
the necessary elements above e.g. driverClassName etc.

In my web.xml for my app I have the following:

  <resource-ref>
    <res-ref-name>jdbc/XXXX</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
  </resource-ref>

To use the pool I have the following code in a servlet:  (I have left out
the try/catch block etc.)

  Context ctx = new InitialContext();
  DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/XXXX");
  conn = ds.getConnection();
  ....

Hope this helps.

Malcolm

-----Original Message-----
From: Sebastiªo Carlos Santos [mailto:scarlosantos@bol.com.br]
Sent: 21 February 2003 00:15
To: tomcat-user@jakarta.apache.org
Subject: Connection Pooling


Somebody has some experience or example in the 
configuration and use of pool of connections with the 
commons-dbcp.  
I am a little lost and I don't know through where to 
begin.  
All information will be well arrival.  
I thank the help in advance

 
__________________________________________________________________________
E-mail Premium BOL
Antivírus, anti-spam e até 100 MB de espaço. Assine já!
http://email.bol.com.br/



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message