Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML

Fresher Job


 

Search Host

Monthly Fee($)
Disk Space (MB)
Register With us for Newsletter!
Visit Forum! Post Questions!
Jobs At RoseIndia.net!

Have tutorials?
Add your tutorial to our Java Resource and get tons of hits.

We offer free hosting for your tutorials. and exposure for thousands of readers. drop a mail
roseindia_net@yahoo.com
 
   

Tutorials

Java Server Pages

JAXB

Java Beans

JDBC

MySQL

Java Servlets

Struts

Bioinformatics

Java Code Examples

Interview Questions

 
Join For Newsletter

Powered by groups.yahoo.com
Visit Group! Post Questions!

Web Promotion

Web Submission

Submit Sites

Manual Submission?

Web Promotion Guide

Hosting Companies

Web Hosting Guide

Web Hosting

Linux

Beginner Guide to Linux Server

Frameworks

Persistence Framework

Web Frameworks

Free EAI Tools

Web Servers

Aspect Oriented Programming

Free Proxy Servers

Softwares

Adware & Spyware Remover

Open Source Softwares

connection pooling
Expert:mamatha
Answers
Hi friend,<br /><br /><br />Connection Pooling :<br /><br />A connection pool is a cache of database connections maintained by the database. <br />This results connections can be reused when the database receives future requests for data.<br />It is used to increase the performance of executing commands on a database.<br />It open and maintain a database connection for each user.<br /><br />In JDBC connection pool, a pool of Connection objects is created at the time the application server (or some other server) starts.<br />These objects are then managed by a pool manager.When the connection pool server starts, it creates a predetermined <br />number of Connection objects.A client application would then perform a JNDI lookup to retrieve a reference to a <br />DataSource object that implements the ConnectionPoolDataSource interface. The ConnectionPoolDataSource would return a <br />Connection object that implemented the PooledConnection interface.<br /><br />For example :<br /><br />import java.sql.*;<br />import java.util.Properties;<br />import org.apache.commons.dbcp.*;<br />import org.apache.commons.pool.impl.*;<br />import org.apache.commons.pool.KeyedObjectPoolFactory;<br /><br /><br />public class JConPool {<br /><br /> public static void main(String args[]) throws Exception {<br /><br /> GenericObjectPool gObjPool = new GenericObjectPool();<br /><br /> Properties pros = new Properties();<br /> pros.setProperty(&quot;Username&quot;, &quot;root&quot;);<br /> pros.setProperty(&quot;Password&quot;, &quot;&quot;);<br /> ConnectionFactory cf = new DriverConnectionFactory(new com.mysql.jdbc.Driver(),&quot;jdbc:<a href="mysql://localhost/commons&quot;,pros"; target="_blank">mysql://localhost/commons&quot;,pros</a>);<br /><br /><br /> KeyedObjectPoolFactory kopf =new GenericKeyedObjectPoolFactory(null, 8);<br /><br /> PoolableConnectionFactory pcf = new PoolableConnectionFactory(cf,gObjPool,kopf, null, false, true);<br /><br /><br /> for(int i = 0; i &lt; 5; i++) {<br /> gObjPool.addObject();<br /> }<br /><br /> <br /> PoolingDriver poold = new PoolingDriver();<br /> poold.registerPool(&quot;example&quot;, gObjPool);<br /><br /> for(int i = 0; i &lt; 5; i++) {<br /> gObjPool.addObject();<br /> }<br /><br /> Connection connection = java.sql.DriverManager.getConnection(&quot;jdbc:apache:commons:dbcp:example&quot;);<br /><br /> System.err.println(&quot;Connection: &quot; + connection ); <br /> PreparedStatement ps = connection.prepareStatement(&quot;Select * from tablename where id = ?&quot;);<br /><br /> System.err.println(&quot;Active: &quot; + gObjPool.getNumActive() + &quot;, Idle: &quot; + gObjPool.getNumIdle());<br /><br /> connection.close();<br /><br /> System.err.println(&quot;Active: &quot; + gObjPool.getNumActive() + &quot;, Idle: &quot; + gObjPool.getNumIdle());<br /><br /> }<br />}<br /><br />Thanks
More Questions
Post Answers
 
Ask Question Facing Programming Problem?
Useful Links
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright 2007. All rights reserved.