0 Replies Latest reply on Feb 26, 2007 11:15 PM by Ashish Kumar Mishra

    How To use Connection Pooling in Struts.

    Ashish Kumar Mishra Newbie

      I m using commons pool, and DBCP.,
      Currently in a Class which implements Plugin interface, i m writing following code,

      GenericObjectPool pool = new GenericObjectPool(null); //

      DataSource datasource = actionServlet.findDataSource("msgds");
      Connection con=datasource.getConnection();
      PoolableConnection pc=new PoolableConnection(con, pool);
      context.setAttribute("con", pc);

      In all each Action, i m using this PoolableConnection as follows:

      PoolableConnection con = (PoolableConnection) context.getAttribute("con");
      Statement st = con.createStatement();

      I just want to know is this method is corrtect n efficient. I had defined datasource in struts-config.xml like this:

      <data-source type="org.apache.commons.dbcp.BasicDataSource" key="msgds">

      <set-property property="description" value="OracleXE Data Source" />
      <set-property property="driverClassName" value="oracle.jdbc.driver.OracleDriver" />

      <set-property property="url" value="jdbc:oracle:thin:@" />

      <set-property property="minCount" value="2" />
      <set-property property="maxCount" value="50" />
      <set-property property="maxWait" value="5000" />
      <set-property property="username" value="ashish" />
      <set-property property="password" value="ashish" />
      <set-property property="autoCommit" value="true" />
      <set-property property="readOnly" value="false" />


      Please help me how to use commons pool and DBCP for connection pooling.