commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "hicham ABASSI" <h.aba...@datapresse.fr>
Subject Questions about jdbc2pooldatasource and cpdsadapter
Date Wed, 04 Jun 2003 07:36:21 GMT
Hy,

I have a JDBC driver v1.0. It doesn't implement the Datasource interface.
This is a Centura SQLBase DB.
I failout to create a JNDI Datasource in Tomcat because this driver doesn't provide Datasource
object.
I need to create a Datasource to using it in JSTL sql tags. (<sql:query... )

i can create datasource in a servletcontextlistener with theses the packages :
  a..     org.apache.commons.dbcp.cpdsadapter
  b..     org.apache.commons.dbcp.jdbc2pool


Here is the theory code :

----------------------------------------------------------------------------------------------
package com.lc.rm.servlets;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.sql.*;
import org.apache.commons.dbcp.*;
import org.apache.commons.dbcp.jdbc2pool.*;
import org.apache.commons.dbcp.cpdsadapter.*;
import javax.servlet.jsp.jstl.core.*;

public class ResourceManagerListener implements ServletContextListener {

    public void contextInitialized(ServletContextEvent sce) {
    
    ServletContext application = sce.getServletContext( );
    
    DataSource ds = null;
    
    try {
        DriverAdapterCPDS cpds = new DriverAdapterCPDS();    
        cpds.setDriver(<JdbcDriverClassName>);
        cpds.setUrl(<jdbcUrl>);
        cpds.setUser(<username>);
        cpds.setPassword(<password>);

        Jdbc2PoolDataSource tds = new Jdbc2PoolDataSource();
        tds.setConnectionPoolDataSource(cpds);
        tds.setDefaultMaxActive(10);
        tds.setDefaultMaxWait(5);
        tds.setDefaultAutoCommit(false);
        tds.setDefaultMaxIdle(1);
        
        ds = tds;
    }
    catch (Exception e) {
      application.log("Error creating connection pool: ", e);
    }
    // Assign this datasource to the default JSTL Datasource
    Config.set(application, Config.SQL_DATASOURCE, ds);
  }
  public void contextDestroyed(ServletContextEvent sce) {
    ServletContext application = sce.getServletContext( );
  }
}
------------------------------------------------------------------------------------
    
But these packages are not released in the 1.0.

Are they stable ?
If not, how to do this with org.apache.commons.dbcp package ?

I need a Datasource, not a driver.
The examples show how to create a PoolDatasource or a PoolDriver.

I regret that i can't create a PoolDatasource with JOCL. is it correct ?
i see that only PoolDriver can read JOCL file.


  a.. tomcat 4.1.24
  b.. commons-dbcp
  c.. SQLBase 7
  d.. Windows2000
  e.. jdk1.4.1_02


Thanks.































Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message