ConnectionPool myPool = ConnectionPool.getInstance();//得到链接池实例
Connection conn=myPool.getConnection(3000);//返回一个链接,设置3秒钟超时
PreparedStatement pstmt = conn.prepareStatement(strSQL);
ResultSet rs = pstmt.executeQuery();

解决方案 »

  1.   

    ConnectionPool.class文件位置怎么放呢,
    classpath怎么加?
      

  2.   

    OK,
    我已经做好了,可是请问这样做有什么好处呢?
    <%
    ConnectionPool myPool = ConnectionPool.getInstance();
    //得到链接池实例
    Connection conn=myPool.getConnection(3000);
    //返回一个链接,设置3秒钟超时
    //PreparedStatement pstmt = conn.prepareStatement();
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("select * from table");
    out.println("<table>");
    while(rs.next()){
    String gys=rs.getString(1);
    String name=rs.getString(2);
    out.println("<tr><td>"+gys+"</td><td>"+name+"</td></tr>");
    }
    out.println("</table>");
    %>
      

  3.   

    好处就是可以控制链接数量和共享对数据库的链接
    全局可以调用该链接,有效的程序不会每次都去建立链接
    用完就释放链接,可以用pool进行对链接管理
      

  4.   

    上面有代码:
    try
    {
    maxConn = Integer.parseInt("100");
    }
    类自己设置了100个最大连接
    你怎么设置5个的?
      

  5.   

    我是说的活动连接为什么不能重复使用呢而是去打开一个新世界连接,
    是不是我的pool的问题?
      

  6.   

    用ConnectionPool和odbc那种比较好?
      

  7.   

    你必须把不用的连接用
    freeConnection方法返回给连接池
    不然pool怎么知道哪个连接没有使用
      

  8.   

    你必须把不用的连接用
    freeConnection方法返回给连接池
    不然pool怎么知道哪个连接没有使用
      

  9.   

    OKOK,THANKS,
    你能谈谈还应该注意什么吗?
    比如这个是不是很好呀?