Principals for connection pools

We are using a dbms realm for our application on a Bea WeblogicServer
5.1 on Solaris
7.
It seems that it is not possible to use a group as principal for
a connection pool in the
weblogic.properties file. This results in a SecurityException when
a user which is a
member of the corresponding group tries to get a connection from
the connection pool.
Does anybody have similar problems or even better a solution or
explanation for this
problem?
Dieter Arnold
GFT Technologies AG
Curiestr. 5
D-70563 Stuttgart-Vaihingen
Tel:+49-711-62042-100, Fax: +49-711-62042-101,
mailto:[email protected]
http://www.gft.com

probably not your problem, but groupnames and usernames should
be unique in weblogic, so if you happen to have a user with the
same name as the group you are trying to use, it would confuse
the server.
but, like I said, probably not your problem.
-Don
"Ken Hu" <[email protected]> wrote:
Dieter,
I got the same problem as yours when I am working with
WLS 5.1:
I have a connection pool set up in the weblogic.properties
file and a Oracle
RDBMSRealm. And there is an acl entry in the database
indicating that a
certain group has 'reserve' right to the connection pool.
Then when one user which in fact belongs to that group
try to use the
connection pool, he will get SecurityException saying
that he doesn't has a
reserve right. But when I change group name of the acl
entry to that user,
he is able to use the connection pool. All seems that
I can't use a group as
principal in the Connection Pool acl settings.
But when I used WLS6.0, the problem disappeared. Does
anybody have any idea?
Thanks,
Ken
Tom Mitchell <[email protected]> wrote in message news:[email protected]..
Dieter,
I am not sure I understand what you are trying to do.a group is a
collection of users and does not have a password. Canyou explain what
you are trying to accomplish?
Thanks.
Dieter Arnold wrote:
It seems that it is not possible to use a group as
principal for
a connection pool in the
weblogic.properties file. This results in a SecurityExceptionwhen
a user which is a--
Tom Mitchell
[email protected]
Very Current Stoneham, MA Weather
http://www.tom.org

Similar Messages

  • Using commons dbcp in SOA 8 for connection pool?

    Hi there,
    It is possible to use commons dbcp in SOA 8 for connection pool ing?
    At far I tried SOA 8 does not work either Mckoi and AS400 databases jdbc drivers in a connection pool.
    So having the experience with Tomcat and commons-dbcp with successfull connection pools, I am trying to use a alternative database connection pool, or use SOA8 connection pool using commons-dbcp and it with our AS400 db.
    Do you think it is possible?
    Thanks for your input!
    Lorenzo Jimenez

    I am really lost.
    All I know i that I used this jtopen driver on tomcat with and without connection pool.
    I used the same parameters, but SOA implementation or program is different. Maybe is the 1.4 api, maybe is the jdbc expected.
    Really don't know.
    What I know I as400 and mckoi drivers don't work where in Tomcat work ok.
    Please check this thread with the error that SOA gave to me
    http://forum.java.sun.com/thread.jsp?forum=136&thread=524472&tstart=0&trange=15
    Thanks,
    Lorenzo

  • Need server.xml and web.xml for connection pooling

    hi guys,
    I am having lots of problem implementing the Connection Pool. I want to use the Tomcat's Connection pool classes and not my connection pool.
    I have gone through lots of problem trying to configure it.
    I got the range of errors. Has someone worked on this. Does it work with Tomcat 4.1 and Oracle 8i. Can anyone provide any links or previous posts to help me out.
    If someone can paste their working server.xml and web.xml then that would be really grt.
    Any kind of help would be really helpful.
    Amit

    Tomcat does not have a connection pooling mechanism. I've used Apache Commons DBCP with Tomcat although with PostgreSQL. It works great.
    Nothing in my web.xml gets modified. Only server.xml needs to be updated for DBCP. The Tomcat JNDI Datasource documentation is very good and should get you through.

  • WebLogic 6.0 SP1 - No JdbcServices for connection pools.

    "My question is what version of WebLogic will the progromatic connection pool creation be re-introduced? Is it available in SP2 or version

    Edit the registry.xml file and change "6.0 Beta" to "6.0"
    -Greg
    On 12 Mar 2001 10:02:19 -0800, "Raman Trikkur" <[email protected]>
    wrote:
    >
    Hello Kumar,
    Here is my registry.xml.
    <?xml version="1.0" encoding="UTF-8"?>
    <bea-product-information>
    <host name="ramantrik2pc">
    <product name="WebLogic Server" format="1.0">
    <release level="6.0 Beta" Status="installed" InstallDir="D:\bea\wlserver6.0"
    InstallTime="Mar 1, 2001 5:18:57 PM" InstallSet="Server">
         <component name="Program" />
         <component name="Samples" />
    </release>
    </product>
    </host>
    </bea-product-information>
    Thanks for helping me figure this out. If this doesn't work,
    I'll just try installing the whole package (WLS 6.0 with SP1
    applied) as Xiang suggested.
    Regards,
    Raman
    Kumar Allamraju <[email protected]> wrote:
    could you post your registry.xml ?
    Raman Trikkur wrote:
    Hi,
    I'm trying to get the service pack SP1 ((wls60sp1_upgrade_win.exe)
    ) installed on my NT box. I have wls 6.0 installed andworking.
    After unpacking and choosing my bea home directory (D:\bea),I
    get an error that says "Weblogic Server Service Pack1 Installation
    failed. You do not seem to have Weblogic server 6.0installed for
    BEAHOME D:\bea".
    But that is untrue. I DO have it installed in D:\bea,and I have
    the environment shell up by running setEnv.cmd and Iinvoked the
    service pack installer from within that shell.
    Is there anything I'm missing? Has anyone else encounteredthis
    problem? Any help with this would be much appreciated.
    Regards,
    Raman

  • Credentialling for Connection Pools

    I've been looking at different documents on dev2dev, but being new to the
    security I'm not sure what I'm looking at. That's at least simple humble
    way to say it.
    Is it possible to configure WebLogic (8.1) server to use external
    credentials for a connection pool?
    Thanks,
    Michael

    probably not your problem, but groupnames and usernames should
    be unique in weblogic, so if you happen to have a user with the
    same name as the group you are trying to use, it would confuse
    the server.
    but, like I said, probably not your problem.
    -Don
    "Ken Hu" <[email protected]> wrote:
    Dieter,
    I got the same problem as yours when I am working with
    WLS 5.1:
    I have a connection pool set up in the weblogic.properties
    file and a Oracle
    RDBMSRealm. And there is an acl entry in the database
    indicating that a
    certain group has 'reserve' right to the connection pool.
    Then when one user which in fact belongs to that group
    try to use the
    connection pool, he will get SecurityException saying
    that he doesn't has a
    reserve right. But when I change group name of the acl
    entry to that user,
    he is able to use the connection pool. All seems that
    I can't use a group as
    principal in the Connection Pool acl settings.
    But when I used WLS6.0, the problem disappeared. Does
    anybody have any idea?
    Thanks,
    Ken
    Tom Mitchell <[email protected]> wrote in message news:[email protected]..
    Dieter,
    I am not sure I understand what you are trying to do.a group is a
    collection of users and does not have a password. Canyou explain what
    you are trying to accomplish?
    Thanks.
    Dieter Arnold wrote:
    It seems that it is not possible to use a group as
    principal for
    a connection pool in the
    weblogic.properties file. This results in a SecurityExceptionwhen
    a user which is a--
    Tom Mitchell
    [email protected]
    Very Current Stoneham, MA Weather
    http://www.tom.org

  • Help needed for Connection Pooling

    I want to know about connection pooling in java.Can anyone suggest a best tutorial or link to learn this.

    http://java.sun.com/developer/onlineTraining/Programming/JDCBook/conpool.html
    http://java.sun.com/products/jndi/tutorial/ldap/connect/pool.html
    or better Google it.

  • Ideas for Connecting Pool Controller to WRT54G

    I am trying to connect a Zodiac iAqualink wireless pool equipment controller to my home network (WRT54G) without success. I need some ideas. This is a 802.11b device. My router is set to mixed mode.
    What I have tried:
    1. Set it up as suggested in the instructions: WEP2 security, double checked SSID and password
    2. Set it up without wireless security
    3. Changed channels
    4. Set mode to 802.11b
    In all cases the LED on the iAqualink that is supposed to indicate that it is connected to the network illuminates properly, but I can never find the device using EasyLink Advisor.
    Help!!

    tnsguy wrote:
    I am trying to connect a Zodiac iAqualink wireless pool equipment controller to my home network (WRT54G) without success. I need some ideas. This is a 802.11b device. My router is set to mixed mode.
    What I have tried:
    1. Set it up as suggested in the instructions: WEP2 security, double checked SSID and password
    2. Set it up without wireless security
    3. Changed channels
    4. Set mode to 802.11b
    In all cases the LED on the iAqualink that is supposed to indicate that it is connected to the network illuminates properly, but I can never find the device using EasyLink Advisor.
    Help!!
    Are there other wireless devices already working thru your router? Because if that is the case then there might be something wrong with how the Aqualink is connecting to the router. Does you aqualink has an option to connect via the wired connection? Just to verify though if that will work via a wired connection. If it won't work via the wired connection then there might be something wrong with the Aqualink device. You may need to call their tech support to get further assistance.

  • How to make connection Pool for standalone Application

    hi
    I have got an application to craete a stadalone appliaction for connection pool.But it is taking m more time to create the Connection and fetch the data.
    import java.sql.*;
    import java.util.*;
    /** A class for preallocating, recycling, and managing
    *  JDBC connections.
    *  <P>
    *  Taken from Core Servlets and JavaServer Pages
    *  from Prentice Hall and Sun Microsystems Press,
    *  http://www.coreservlets.com/.
    *  &copy; 2000 Marty Hall; may be freely used or adapted.
    public class ConnectionPool implements Runnable {
      private String driver, url, username, password;
      private int maxConnections;
      private boolean waitIfBusy;
      private Vector availableConnections, busyConnections;
      private boolean connectionPending = false;
      public ConnectionPool(String driver, String url,
                            String username, String password,
                            int initialConnections,
                            int maxConnections,
                            boolean waitIfBusy)
          throws SQLException {
        this.driver = driver;
        this.url = url;
        this.username = username;
        this.password = password;
        this.maxConnections = maxConnections;
        this.waitIfBusy = waitIfBusy;
        if (initialConnections > maxConnections) {
          initialConnections = maxConnections;
        availableConnections = new Vector(initialConnections);
        busyConnections = new Vector();
        for(int i=0; i<initialConnections; i++) {
          availableConnections.addElement(makeNewConnection());
      public synchronized Connection getConnection()
          throws SQLException {
        if (!availableConnections.isEmpty()) {
          Connection existingConnection =
            (Connection)availableConnections.lastElement();
          int lastIndex = availableConnections.size() - 1;
          availableConnections.removeElementAt(lastIndex);
          // If connection on available list is closed (e.g.,
          // it timed out), then remove it from available list
          // and repeat the process of obtaining a connection.
          // Also wake up threads that were waiting for a
          // connection because maxConnection limit was reached.
          if (existingConnection.isClosed()) {
            notifyAll(); // Freed up a spot for anybody waiting
            return(getConnection());
          } else {
            busyConnections.addElement(existingConnection);
            return(existingConnection);
        } else {
          // Three possible cases:
          // 1) You haven't reached maxConnections limit. So
          //    establish one in the background if there isn't
          //    already one pending, then wait for
          //    the next available connection (whether or not
          //    it was the newly established one).
          // 2) You reached maxConnections limit and waitIfBusy
          //    flag is false. Throw SQLException in such a case.
          // 3) You reached maxConnections limit and waitIfBusy
          //    flag is true. Then do the same thing as in second
          //    part of step 1: wait for next available connection.
          if ((totalConnections() < maxConnections) &&
              !connectionPending) {
            makeBackgroundConnection();
          } else if (!waitIfBusy) {
            throw new SQLException("Connection limit reached");
          // Wait for either a new connection to be established
          // (if you called makeBackgroundConnection) or for
          // an existing connection to be freed up.
          try {
            wait();
          } catch(InterruptedException ie) {}
          // Someone freed up a connection, so try again.
          return(getConnection());
      // You can't just make a new connection in the foreground
      // when none are available, since this can take several
      // seconds with a slow network connection. Instead,
      // start a thread that establishes a new connection,
      // then wait. You get woken up either when the new connection
      // is established or if someone finishes with an existing
      // connection.
      public void makeBackgroundConnection() {
        connectionPending = true;
        try {
          Thread connectThread = new Thread(this);
          connectThread.start();
        } catch(OutOfMemoryError oome) {
          // Give up on new connection
      public void run() {
        try {
          Connection connection = makeNewConnection();
          synchronized(this) {
            availableConnections.addElement(connection);
            connectionPending = false;
            notifyAll();
        } catch(Exception e) { // SQLException or OutOfMemory
          // Give up on new connection and wait for existing one
          // to free up.
      // This explicitly makes a new connection. Called in
      // the foreground when initializing the ConnectionPool,
      // and called in the background when running.
      public Connection makeNewConnection()
          throws SQLException {
        try {
          // Load database driver if not already loaded
          Class.forName(driver);
          // Establish network connection to database
          Connection connection =
            DriverManager.getConnection(url, username, password);
          return(connection);
        } catch(ClassNotFoundException cnfe) {
          // Simplify try/catch blocks of people using this by
          // throwing only one exception type.
          throw new SQLException("Can't find class for driver: " +driver);
      public synchronized void free(Connection connection) {
        busyConnections.removeElement(connection);
        availableConnections.addElement(connection);
        // Wake up threads that are waiting for a connection
        notifyAll();
      public synchronized int totalConnections() {
        return(availableConnections.size() +
               busyConnections.size());
      /** Close all the connections. Use with caution:
       *  be sure no connections are in use before
       *  calling. Note that you are not <I>required</I> to
       *  call this when done with a ConnectionPool, since
       *  connections are guaranteed to be closed when
       *  garbage collected. But this method gives more control
       *  regarding when the connections are closed.
      public synchronized void closeAllConnections() {
        closeConnections(availableConnections);
        availableConnections = new Vector();
        closeConnections(busyConnections);
        busyConnections = new Vector();
      public void closeConnections(Vector connections) {
        try {
          for(int i=0; i<connections.size(); i++) {
            Connection connection =
              (Connection)connections.elementAt(i);
            if (!connection.isClosed()) {
              connection.close();
        } catch(SQLException sqle) {
          // Ignore errors; garbage collect anyhow
      public synchronized String toString() {
        String info =
          "ConnectionPool(" + url + "," + username + ")" +
          ", available=" + availableConnections.size() +
          ", busy=" + busyConnections.size() +
          ", max=" + maxConnections;
        return(info);
    }///// The Calling Class is below---------/////////////////
    import java.util.*;
    import java.sql.*;
    public class dbConnection
         public static void main(String[] args)
              String driver="oracle.jdbc.driver.OracleDriver";
              String username="ETS";
              String password="ETS";
              String url="jdbc:oracle:thin:@192.168.47.10:1521:ETS";
              int initialConnections=10;
            int maxConnections=50;
              boolean waitIfBusy=false;
              Connection con=null;
              Statement stmt = null;
              ResultSet rs = null;
              try
              System.out.println("Before constructory "+new java.util.Date());
              ConnectionPool pool=new ConnectionPool(driver,url,username,password,initialConnections,maxConnections,waitIfBusy);
              System.out.println("After constructory "+new java.util.Date());
                        con=pool.makeNewConnection();
         System.out.println("After Connection pool "+new java.util.Date());
                        String sql="select * from emp_master";
                        stmt = con.createStatement();
                        rs = stmt.executeQuery(sql);
                        while(rs.next()) {
                   int login1=rs.getInt("emp_code");     
                        System.out.println("Employee Code is  "+login1);
                        System.out.println("check 2");
                   String pass=rs.getString("PASSWORD");
                        System.out.println("Pass Word is "+pass);
              }catch(Exception e)
                   System.out.println("Exception is "+e);
              finally {
    }

    I once created a connection pool programatically with Apache DBCP API. It didnt took more than 10 lines. Unforchunetly I dont have to code with me now.
    But If I remember right there is a sample code for that in the Apache Commans DBCP documentation.

  • Requirements for JDBC Driver needed for SOA 8 }connection pool

    Hi,
    I have an AS400 jdbc driver. This driver is JDBC API version 2.x. Also is a Driver Type 4.
    What are the requirements of a JDBC Driver needed for connection pool in SOA 8?
    Thanks.
    Lorenzo Jimenez

    You can use pretty much any jdbc driver, including type 2 and type 4.
    You need to make sure your shared libraries needed by the driver are available to the appserver when you boot.
    Other than that, it is no different than configuring any other driver.

  • How database connection pooling works in a application

    Hi Guys,
    I am new to Java and looking into best way of doing J2ee database conectivity. I am using Eclipse galileo3.5 J2EE with Mysql database and Tomcate 6.0.
    I am developing an email application where I need to implement MVC model for my webapplication, using jsp for presentation, servlet for control and java beans for model.
    I came across two tutorial for database connection pooling as given below.
    Eclipse Corner Article: Creating Database Web Applications with Eclipse - In this tutorial connection pooling is configure in Tomcate 6.0
    It says Copy and paste the following into your context.xml file (you may have to click on the Source tab at the bottom of the editor to be able to paste). This defines a DataSource with the name "jdbc/SampleDB". Our application will retrieve database connections from the pool using this name.
    <?xml version="1.0" encoding="UTF-8"?>
    <Context>
    <Resource name="jdbc/SampleDB" auth="Container"
    type="javax.sql.DataSource"
    username="app" password="app"
    driverClassName="org.apache.derby.jdbc.ClientDrive r"
    url="jdbc:derby://localhost:1527/sample"
    maxActive="8" />
    </Context>
    Where as in second tutorial - http://www.roseindia.net/answers/viewanswers/2838.html
    It uses java bean for connection pooling and then use straight way in JSP and no Servlet used.
    conpool.jsp
    <%@page import="java.sql.Connection"%>
    <jsp:useBean id="pl" class="com.CoreJava.ConnectionPooling"/>
    <% Connection con = pl.getConnection(); %>
    //do something using con
    connectionPooling.java
    import com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolD ataSource;
    public class ConnectionPooling
    static Connection con=null;
    public static Connection getConnection()
    try
    MysqlConnectionPoolDataSource po=new MysqlConnectionPoolDataSource();
    po.setServerName("localhost");
    po.setPortNumber(3306);
    po.setDatabaseName("mydatabase"); //changeur database name
    po.setUser("root");//ur username
    po.setPassword("");//ur password
    con = po.getConnection();
    catch(Exception e)
    System.out.println("Exception Connection :"+e);
    return con;
    Please some one explain which is the best way of doing connection pooling to the database by using MVC pattern
    Please if some one advise me how to use MVC architecture for simple email application and database connectivty.
    Thanks

    >
    >
    Where as in second tutorial - http://www.roseindia.net/answers/viewanswers/2838.html
    Never EVER use roseindia. It is terrible shit.
    [http://balusc.blogspot.com/2008/06/what-is-it-with-roseindia.html]
    The correct answer is what you found in the eclipse article. And you can read the Tomcat docs for more.
    As per usual the code you have posted from Roseindia is a big pile of rubbish that was written by a complete idiot. I mean the person who wrote it apparently doesn't know much Java at all. Let alone JDBC. Or Connection pools. Or J2EE. It's not the worst I've seen from them but it's pretty bad.

  • Questions on Connection Pooling

    I already read the documentations on data-sources.xml, but I still have questions. In the following data-sources.xml (for OC4J 9.0.3):
    <data-source
    class="com.evermind.sql.ConnectionDataSource"
    name="ccf"
    location="jdbc/ccf"
    xa-location="jdbc/xa/ccf"
    ejb-location="jdbc/ccfPool"
    url="jdbc:oracle:thin:@erb:1521:prod"
    connection-driver="oracle.jdbc.driver.OracleDriver"
    username="scott"
    password="tiger"
    max-connections="300"
    min-connections="5"
    max-connect-attempts="10"
    connection-retry-interval="1"
    inactivity-timeout="30"
    wait-timeout="30"
    />
    I know that if we want to use a connection pool, we should use "ejb-location" and it is the only one used for emulated data sources. I also know that both "location" and "xa-connection" are used for non-emulated data sources.
    Then my questions are:
    1) Does non-emulated data source mean that it can not used for connection pooling? In other words, both "location" and "xa-location" can not be used for connection pooling? The only one that can be used for connection pooling is "ejb-location"?
    2) How can I use a non-pooled connection? right now, I am using "location" for non-connnection pooling, is this the right way to do it? The documentation says that it will be deprecated in future release, then what should I use if I want a non-pooled connection? can I still use "ejb-location" by setting "min-connections" and "max-connections" to 1? This is assuming that we can NOT use "location" to get the data source.
    3) Putting the username and password in the data-sources.xml seems not be good from the security point of view. But, if I am using CMP, I must supply the username and password in the data-sources.xml. Is there another way around this?
    Thank you very much for the help in advance.
    Jingzhi

    Liu
    I may not answer all ur questions.But would like to share my experiences....
    3) U can set the username and password dynamically also...we use it in orion..so u should be able to use it in oc4j..as a matter of fact, we can set all the data-sources parameters dynamically(programmatically).
    1) I may not be correct 100 percent with this :but for pooling only ejb-location is used and for non pooling location is used.
    For non pooled connections also, use ejb-location and dont give any max and min connections..let it take the default values...
    I am not aware that Oracle is going to deprecate the location ..well it is good to hear this which will reduce some confusion..
    seems there is lot being raised on these topics..
    yugandhar

  • Connection Pooling Questions

    Hi there,
    I was previously using the jferner/node-oracle module with the "generic-pool" (https://github.com/coopernurse/node-pool) module for connection pooling. 
    I'm trying out a setup with connection pooling with node-oracledb and have a few questions:
    * If an execute call fails with a connection i've retrieved from the pool, and I want to destroy that connection and remove it from the pool, how do I do that?  Is it done implicitly for me? 
    * Is there any way to validate a connection before it's used?  Or again, is this done implicitly?  Is there a way to toggle it on and off for perf tuning?
    * Is there any way to tune how frequently Oracle checks for idle connections?  (In generic-pool this was called reapIntervalMillis)
    * Is there any way to turn on any logging of how the connection pool behaves for development debugging?  I just want to make sure my setup is behaving as I think it should be.
    I'm making some good headway on getting the module working and it wasn't too difficult a conversion from node-oracle, either, that's good!
    -Matt

    You should release() bad connections to the pool so the pool can replace them.
    Validating connections is generally not worth it: between validation & use there could be a failure, so your executions need to handle errors anyway.  Why reduce scalability and performance by doing an extra "round trip" for validation? Also you can use FAN which can proactively clean up idle sessions in the session pool that are affected by the DB instance disappearing (due to network glitches etc).
    The client-side pool is handled by Oracle session pooling, so the algorithms are opaque.

  • Setting up a connection pool to ms sql database

    Hi
    I am trying to create a connection pool to talk to an MSSQL database, and could not manage to ping the DB (Operation 'pingConnectionPool' failed in 'resources' Config Mbean.) .
    What set of properties need to be included for connection pool to an MS SQL DB?
    your help is very much appreciated,
    Yhank you
    orms2004

    package coreservlets;
    import java.sql.*;
    import java.util.*;
    /** A class for preallocating, recycling, and managing
    *  JDBC connections.
    *  <P>
    *  Taken from Core Servlets and JavaServer Pages
    *  from Prentice Hall and Sun Microsystems Press,
    *  http://www.coreservlets.com/.
    *  &copy; 2000 Marty Hall; may be freely used or adapted.
    public class ConnectionPool implements Runnable {
      private String driver, url, username, password;
      private int maxConnections;
      private boolean waitIfBusy;
      private Vector availableConnections, busyConnections;
      private boolean connectionPending = false;
      public ConnectionPool(String driver, String url,
                            String username, String password,
                            int initialConnections,
                            int maxConnections,
                            boolean waitIfBusy)
          throws SQLException {
        this.driver = driver;
        this.url = url;
        this.username = username;
        this.password = password;
        this.maxConnections = maxConnections;
        this.waitIfBusy = waitIfBusy;
        if (initialConnections > maxConnections) {
          initialConnections = maxConnections;
        availableConnections = new Vector(initialConnections);
        busyConnections = new Vector();
        for(int i=0; i<initialConnections; i++) {
          availableConnections.addElement(makeNewConnection());
      public synchronized Connection getConnection()
          throws SQLException {
        if (!availableConnections.isEmpty()) {
          Connection existingConnection =
            (Connection)availableConnections.lastElement();
          int lastIndex = availableConnections.size() - 1;
          availableConnections.removeElementAt(lastIndex);
          // If connection on available list is closed (e.g.,
          // it timed out), then remove it from available list
          // and repeat the process of obtaining a connection.
          // Also wake up threads that were waiting for a
          // connection because maxConnection limit was reached.
          if (existingConnection.isClosed()) {
            notifyAll(); // Freed up a spot for anybody waiting
            return(getConnection());
          } else {
            busyConnections.addElement(existingConnection);
            return(existingConnection);
        } else {
          // Three possible cases:
          // 1) You haven't reached maxConnections limit. So
          //    establish one in the background if there isn't
          //    already one pending, then wait for
          //    the next available connection (whether or not
          //    it was the newly established one).
          // 2) You reached maxConnections limit and waitIfBusy
          //    flag is false. Throw SQLException in such a case.
          // 3) You reached maxConnections limit and waitIfBusy
          //    flag is true. Then do the same thing as in second
          //    part of step 1: wait for next available connection.
          if ((totalConnections() < maxConnections) &&
              !connectionPending) {
            makeBackgroundConnection();
          } else if (!waitIfBusy) {
            throw new SQLException("Connection limit reached");
          // Wait for either a new connection to be established
          // (if you called makeBackgroundConnection) or for
          // an existing connection to be freed up.
          try {
            wait();
          } catch(InterruptedException ie) {}
          // Someone freed up a connection, so try again.
          return(getConnection());
      // You can't just make a new connection in the foreground
      // when none are available, since this can take several
      // seconds with a slow network connection. Instead,
      // start a thread that establishes a new connection,
      // then wait. You get woken up either when the new connection
      // is established or if someone finishes with an existing
      // connection.
      private void makeBackgroundConnection() {
        connectionPending = true;
        try {
          Thread connectThread = new Thread(this);
          connectThread.start();
        } catch(OutOfMemoryError oome) {
          // Give up on new connection
      public void run() {
        try {
          Connection connection = makeNewConnection();
          synchronized(this) {
            availableConnections.addElement(connection);
            connectionPending = false;
            notifyAll();
        } catch(Exception e) { // SQLException or OutOfMemory
          // Give up on new connection and wait for existing one
          // to free up.
      // This explicitly makes a new connection. Called in
      // the foreground when initializing the ConnectionPool,
      // and called in the background when running.
      private Connection makeNewConnection()
          throws SQLException {
        try {
          // Load database driver if not already loaded
          Class.forName(driver);
          // Establish network connection to database
          Connection connection =
            DriverManager.getConnection(url, username, password);
          return(connection);
        } catch(ClassNotFoundException cnfe) {
          // Simplify try/catch blocks of people using this by
          // throwing only one exception type.
          throw new SQLException("Can't find class for driver: " +
                                 driver);
      public synchronized void free(Connection connection) {
        busyConnections.removeElement(connection);
        availableConnections.addElement(connection);
        // Wake up threads that are waiting for a connection
        notifyAll();
      public synchronized int totalConnections() {
        return(availableConnections.size() +
               busyConnections.size());
      /** Close all the connections. Use with caution:
       *  be sure no connections are in use before
       *  calling. Note that you are not <I>required</I> to
       *  call this when done with a ConnectionPool, since
       *  connections are guaranteed to be closed when
       *  garbage collected. But this method gives more control
       *  regarding when the connections are closed.
      public synchronized void closeAllConnections() {
        closeConnections(availableConnections);
        availableConnections = new Vector();
        closeConnections(busyConnections);
        busyConnections = new Vector();
      private void closeConnections(Vector connections) {
        try {
          for(int i=0; i<connections.size(); i++) {
            Connection connection =
              (Connection)connections.elementAt(i);
            if (!connection.isClosed()) {
              connection.close();
        } catch(SQLException sqle) {
          // Ignore errors; garbage collect anyhow
      public synchronized String toString() {
        String info =
          "ConnectionPool(" + url + "," + username + ")" +
          ", available=" + availableConnections.size() +
          ", busy=" + busyConnections.size() +
          ", max=" + maxConnections;
        return(info);
    }taken from:
    http://archive.coreservlets.com/Chapter18.html

  • Connection pooling in JSF

    Hi Guys,
    Is it possible to do connection pooling using JSF XML configuration files(Like using<data-sources> tag in struts though it was depricated in struts 1.3.5) or is there any alternative way to do connection pooling in JSF. could any one suggest me plz.
    Regards,
    A.

    Connection pooling is an orthogonal concern to JSF. While it doesn't provide any facilities for connection pooling, there is no reason any existing connection pooling solutions could not be used in concert with it.
    Finally, I would point out that you if you are using JSF in a JEE environment, it is likely that your application server provides connection pooling.

  • MySQL - Connection Pooling - Driver?

    Hi there!
    I am looking for a JDBC 2.0 compatible driver to use with MySQL. I would like to use connection pooling in a webapplication (JSP:s and Servlets) but I have just found out that the driver I usually use mmmysql do not support connection pooling. Hence, my question: Where can I find a driver to use with MySQL with support for Connection Pooling?
    bw

    have you tried resin..
    http://www.caucho.com/projects/jdbc-mysql/index.xtp
    i haven't checked it yet but it could be an option
    i'm currently using mmmysql driver also...I tried that driver and when I had more than one statement open at the same time, it gave me garbage results and then threw an exception. So I'm using the mmmysql driver too.

Maybe you are looking for