据我所知道PreparedStatement方法在IBM的REDBOOKS中是提倡的开发方法。
对你的问题我建议你,在程序连接结束后,手动关闭连接池,这样就会没有问题的。
同时你可以在WAS上进行培植,参阅哪个REDBOOKS。

解决方案 »

  1.   

    你是用connection.close()返回的连接吗?
    我想看看出错信息.
      

  2.   

    我用的是connection.close()返回的连接,但是这个方法在 ConnectionWrapper类中已经被重载了,并不是要关闭连接,只是需要把它返回到连接池中,也就是把连接的状态变为0,
    释放连接的代码为:
    int thisconn = idOfConnection(conn);
    if (thisconn >= 0) {
       connStatus[thisconn] = 0;
       res = "freed " + conn.toString();
       log.println("Freed connection " + String.valueOf(thisconn) +
       " normal exit: ");
    } else {
       log.println("----> Could not free connection!!!");
    }现在的问题出在idOfConnection(conn)这个方法上:
    public int idOfConnection(Connection conn) {
       int match;
       String tag;
       try {
           tag = conn.toString();
       } catch (NullPointerException e1) {
           tag = "none";
       }
       //System.out.println("currCon:" + tag);
       match = -1;
       for (int i = 0; i < currConnections; i++) {
           //System.out.println("con:" + connID[i]);
           if (connID[i].equals(tag)) {
               match = i;
               break;
           }
        }
        return match;
    }
    当我使用PreparedStatement方法时,tag值为:
    DB2Connection 
    {
        connectionHandle = 6 //连接句柄
        SPConnected = false
        source = etool
        user = db2inst1
        conArgs = 
        closed = false
        describeCached = true
        describeParam = true
        isReadOnly = false
        autoClose = false
    }当我使用Statement方法时,tag值为:
    DB2Connection 
    {
        connectionHandle = 6 //连接句柄
        SPConnected = false
        source = etool
        user = db2inst1
        conArgs = 
        closed = false
        describeCached = false
        describeParam = true
        isReadOnly = false
        autoClose = false
    }其中describeCached 这一项变了,
    而connID[i]保存有连接池中所有连接的属性,他们的值都是:DB2Connection 
    {
        connectionHandle = 6 //连接句柄
        SPConnected = false
        source = etool
        user = db2inst1
        conArgs = 
        closed = false
        describeCached = false
        describeParam = true
        isReadOnly = false
        autoClose = false
    }所以造成的结果是idOfConnection(Connection conn)总是返回-1,所以连接无法返回连接池中,小弟万般无耐,只有加上:
    tag = StringUtils.replace(tag, "describeCached = true","describeCached = false");
    才解决目前的困境,是不是用了PreparedStatement方法后连接的describeCached属性就被改为true了啊,Websphere中有什么设置吗?