• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

please tell me why really connection pool is needed

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi friends in the bellow code, i created a single Connection object by using Util() method and same will be given to my all servlets and jsp.
here my doubt is this connection object is single turn object for all my programs which means this connection object opens a one connection in a database and it sharable to all programs, so on database connection burden is reduced, then why i need to go connection pooling concept in jdbc. please anybody can clear my confusion

Jdbc.java

import java.sql.Connection;
import java.sql.DriverManager;

public class Jdbc
{
private static Connection con;
public static Connection util()throws Exception
{
if(con==null)
{
Class.forName("oracle.jdbc.OracleDriver");
con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "root");
}
return con;
}
}
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So what happens when more than one person tries to use your web application?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
P.S. Ignoring that this is a bad idea to begin with, the method Util() is very badly named. First of all, Java methods should start with a lowercase character. Secondly, it doesn't say anything at all about what the method does. A much better method name would be makeConnection(), or something along those lines.
 
Ranch Hand
Posts: 258
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By connection pooling may be using some server it ensures that some connections are reserved for your application with database. Once you ask for it, it gives connections from the connection pool. Make sure you close the connection once used in your program. this again makes it available in connection pool for other requests. This way connection pooling works.

Cheers !!!
 
Ranch Hand
Posts: 93
Python Redhat Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess its 'Singleton' that you are referring to, not 'Single turn' !!.


Now regarding connection pool, one obvious reason is the execution speed on multi-user environment. Obtaining a connection and then commit/rollback and closing it everytime is resource intensive and affects performance.
 
You save more money with a clothesline than dozens of light bulb purchases. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic