你的用法可能不对。你所说的不用连接池是直接在程序里面Class.forName(...?
还是也用了DataSource?。

解决方案 »

  1.   

    有没有配置resource-ref在web.xml中?
    <resource-ref>
      <description>
      </description>
      <res-ref-name>
        jdbc/xgxdb
      </res-ref-name>
      <res-type>
        javax.sql.DataSource
      </res-type>
      <res-auth>
        Container
      </res-auth>
    </resource-ref>还有不需要配置factory了吧,Tomcat4使用了
    org.apache.naming.factory.DbcpDataSourceFactory
      

  2.   

    to  warmship(warmship) 
      在我的应用当中,我
    <resource-ref>
    --
    </resource-ref>
    这个我定义了。org.apache.naming.factory.DbcpDataSourceFactory
    这个不用定义吗??????在文档当中幼这个定义吧。
    我直接用了Class.forName(...?  这个是可以的
    救救我芽
      

  3.   

    to  warmship(warmship)  
    我按照你的方法,把org.apache.naming.factory.DbcpDataSourceFactory
    这个定义去掉,仍旧是connont load jdbc driver class 'null' 的错误。
    不知道改如何办我
      

  4.   

    oracle.jdbc.driver.OracleDriver
    class12.jar你放哪儿了?
    如果用了DataSource,这个class12.jar就得要
    放到 common/lib下了。
    放在Context的WEB-INF/lib下面是不行的,只能被所在的
    Context所使用。
    我只能想到这个原因了。
    good luck.
      

  5.   

    tomcat 4.x版的连接池数据源还处在试用阶段,为什么选用它呢?研究了一会儿,配置成功却发现query出来的数据根本就不对劲,但是插入却是正常的。你的错误提示是找不到jdbc driver,你把它放哪了?只能放在tomcat/common/lib/下面,别处绝对不行,这里官方文档里讲的,我配置dbcp时是按tomcat的帮助文档来配的,拷贝两三下,再修改几处就搞定了,没啥问题呀!
      

  6.   

    呵呵,单看tomcat的DBCP不能为特定的数据库,添加特定参数(与weblogic的差距,不可以道理计),就知它有多差了,还是换一个连接池工具吧,比如PoolMan之类的第三方工具包也很好呀!
      

  7.   

    to peacock_king(孔雀王) 
     我随便写了几句代码,用连接池来访问数据库,可以。
    但是我把这个测试文件放到应用Zjxgx下面去测试的时候,旧报
    Cannot load JDBC driver class 'null' 这个错误,救命芽。
    能够在qq上聊聊吗9620678
      

  8.   

    to peacock_king(孔雀王) 我不同意你的说法,PoolMan是比较垃圾的,bug很多,不稳定。
    DBCP是jakarta commons里面的一个project。它是基于
    jakarta另一个项目 pool的。看看它们的source,还是写得很不错的。
    看你怎么用它的了,加个参数事很容易的,可以在url后面,也可以
    用properties。我是比较相信jakarta的:)。
    实现一个pool并不难,但要实现的好其实并不容易。
    weblogic提供的pool是不错,提供多种方式访问数据源,
    不过它却把oracle的driver打在自己的
    package中我就觉得很搞笑了,xml parser也不让用别家的,非得
    用System.setProperty给替换掉,这样自负的东西让人反感。
      

  9.   

    发送者 peacock_king 发送时间 2003-4-17 10:39:13 加个参数很容易?
    你在url里试过吗
    我这里是不行,还有properties这个东西,在server.xml里能添加吗?回答:
    不同的jdbc driver的connection url的参数的形式不一样。普遍的一种
    类似于http的url的参数: /url?name=value&name1=value1 如oracle, mysql等
    具体的要查一下相对应得jdbc driver的文档。如果想用properties的话,自己可以扩充org.apache.commons.dbcp.BasicDataSourceFactory
    public Object getObjectInstance(Object obj, Name name, Context nameCtx,
                                        Hashtable environment)
            throws Exception {        // We only know how to deal with <code>javax.naming.Reference</code>s
            // that specify a class name of "javax.sql.DataSource"
            if ((obj == null) || !(obj instanceof Reference)) {
                return (null);
            }
            Reference ref = (Reference) obj;
            if (!"javax.sql.DataSource".equals(ref.getClassName())) {
                return (null);
            }        // Create and configure a BasicDataSource instance based on the
            // RefAddr values associated with this Reference
            BasicDataSource dataSource = new BasicDataSource();
            RefAddr ra = null;        ra = ref.get("defaultAutoCommit");
            if (ra != null) {
                dataSource.setDefaultAutoCommit
                    (Boolean.valueOf(ra.getContent().toString()).booleanValue());
            }        ra = ref.get("defaultReadOnly");
            if (ra != null) {
                dataSource.setDefaultReadOnly
                    (Boolean.valueOf(ra.getContent().toString()).booleanValue());
            }        ra = ref.get("driverClassName");
            if (ra != null) {
                dataSource.setDriverClassName(ra.getContent().toString());
            }        ra = ref.get("maxActive");
            if (ra != null) {
                dataSource.setMaxActive
                    (Integer.parseInt(ra.getContent().toString()));
            }        ra = ref.get("maxIdle");
            if (ra != null) {
                dataSource.setMaxIdle
                    (Integer.parseInt(ra.getContent().toString()));
            }        ra = ref.get("maxWait");
            if (ra != null) {
                dataSource.setMaxWait
                    (Long.parseLong(ra.getContent().toString()));
            }        ra = ref.get("testOnBorrow");
            if (ra != null) {
                dataSource.setTestOnBorrow
                    (Boolean.valueOf(ra.getContent().toString()).booleanValue());
            }        ra = ref.get("testOnReturn");
            if (ra != null) {
                dataSource.setTestOnReturn
                    (Boolean.valueOf(ra.getContent().toString()).booleanValue());
            }        ra = ref.get("timeBetweenEvictionRunsMillis");
            if (ra != null) {
                dataSource.setTimeBetweenEvictionRunsMillis
                    (Long.parseLong(ra.getContent().toString()));
            }        ra = ref.get("numTestsPerEvictionRun");
            if (ra != null) {
                dataSource.setNumTestsPerEvictionRun
                    (Integer.parseInt(ra.getContent().toString()));
            }        ra = ref.get("minEvictableIdleTimeMillis");
            if (ra != null) {
                dataSource.setMinEvictableIdleTimeMillis
                    (Long.parseLong(ra.getContent().toString()));
            }        ra = ref.get("testWhileIdle");
            if (ra != null) {
                dataSource.setTestWhileIdle
                    (Boolean.valueOf(ra.getContent().toString()).booleanValue());
            }        ra = ref.get("password");
            if (ra != null) {
                dataSource.setPassword(ra.getContent().toString());
            }        ra = ref.get("url");
            if (ra != null) {
                dataSource.setUrl(ra.getContent().toString());
            }        ra = ref.get("username");
            if (ra != null) {
                dataSource.setUsername(ra.getContent().toString());
            }        ra = ref.get("validationQuery");
            if (ra != null) {
                dataSource.setValidationQuery(ra.getContent().toString());
            }        ra = ref.get("removeAbandoned");
            if (ra != null) {
                dataSource.setRemoveAbandoned
                    (Boolean.valueOf(ra.getContent().toString()).booleanValue());
            }        ra = ref.get("removeAbandonedTimeout");
            if (ra != null) {     
                dataSource.setRemoveAbandonedTimeout
                    (Integer.parseInt(ra.getContent().toString()));
            }        ra = ref.get("logAbandoned");
            if (ra != null) {
                dataSource.setLogAbandoned
                    (Boolean.valueOf(ra.getContent().toString()).booleanValue());
            }        // Return the configured data source instance
            return (dataSource);    }这是它原来的代码,其中的dataSource是BasicDataSource,BaseicDataSource中
    有addConnectionProperty这个方法,你只需要在自己的子类中添加一下
    public Object getObjectInstance(Object obj, Name name, Context nameCtx,
                                        Hashtable environment)
         throws Exception { (BasicDataSource) dataSource = super.getObjectInstance(obj, name, nameCtx, environment);
    Reference ref = (Reference) obj;

    if (dataSource != null) {
    String props = ref.get("props");
    // split props ....
    // name,value
    dataSource.addConnectionProperty(name, value);
    }

    return dataSource
    }最后要把自己的class放到common/classes中。你可以自己定porperties的格式。
    就可以定义在server.xml中了.
      

  10.   

    谢谢各位老大的回答,在这里我还要问几个问题。
    连接池的sql语句,和普通的好像有点差别吧,我不用连接池的时候有些页面能够正常显示,但是用了连接池之后,有些地方报java.lang.nullpointer错误,不知道什么原因。
      

  11.   

    用了pool后要记得close啊。
    系统崩溃指的是什么?