Topic: 有没有连接池的资料,小弟最近的工作需要经常用到数据库

  Print this page

1.有没有连接池的资料,小弟最近的工作需要经常用到数据库 Copy to clipboard
Posted by: ysheng
Posted on: 2004-04-06 11:49

数据库连接要求稳定高效
但是平时只是做做小程序用到
真正的在工作中还没有用到
各位能否给点资料,或者经验之谈Smile

2.Re:有没有连接池的资料,小弟最近的工作需要经常用到数据库 [Re: ysheng] Copy to clipboard
Posted by: zhangtm
Posted on: 2004-04-06 12:35

关注中。。。哪位有呀?

3.Re:有没有连接池的资料,小弟最近的工作需要经常用到数据库 [Re: ysheng] Copy to clipboard
Posted by: mochow
Posted on: 2004-04-06 14:47

直接到sun网站上下个jdbc规范看看吧,应该有的

4.Re:有没有连接池的资料,小弟最近的工作需要经常用到数据库 [Re: ysheng] Copy to clipboard
Posted by: zhangtm
Posted on: 2004-04-06 16:02

楼主,我有个连接池的例子。因为太长了,不便在这写,要的话可以加我的msn:zhangtm@lianchuang.com,不过我没看懂poolmanager.

5.Re:有没有连接池的资料,小弟最近的工作需要经常用到数据库 [Re: zhangtm] Copy to clipboard
Posted by: Jove
Posted on: 2004-04-06 16:23

jakarta.apache.org/commons/dbcp

6.Re:有没有连接池的资料,小弟最近的工作需要经常用到数据库 [Re: ysheng] Copy to clipboard
Posted by: jigsaw
Posted on: 2004-04-06 17:29

为什么不用app server带的呢?

7.Re:有没有连接池的资料,小弟最近的工作需要经常用到数据库 [Re: ysheng] Copy to clipboard
Posted by: flowerknight
Posted on: 2004-04-06 19:45

Tomcat4.1.24+Mysql连接池配法
修改server.xml
1、<!-- Tomcat Root Context -->
(1)、教程用例
<Context path="" docBase="ROOT" debug="0">
<Logger className="org.apache.catalina.logger.FileLogger"
prefix="localhost_DBTest_log." suffix=".txt"
timestamp="true"/>

<Resource name="jdbc/MysqlDB"
auth="Container"
type="javax.sql.DataSource"/>

<ResourceParams name="jdbc/MysqlDB">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>

<!-- Maximum number of dB connections in pool. Make sure you
configure your mysqld max_connections large enough to handle
all of your db connections. Set to 0 for no limit.
-->
<parameter>
<name>maxActive</name>
<value>100</value>
</parameter>

<!-- Maximum number of idle dB connections to retain in pool.
Set to 0 for no limit.
-->
<parameter>
<name>maxIdle</name>
<value>30</value>
</parameter>

<!-- Maximum time to wait for a dB connection to become available
in ms, in this example 10 seconds. An Exception is thrown if
this timeout is exceeded. Set to -1 to wait indefinitely.
-->
<parameter>
<name>maxWait</name>
<value>10000</value>
</parameter>

<!-- MySQL dB username and password for dB connections -->
<parameter>
<name>username</name>
<value>sa</value>
</parameter>
<parameter>
<name>password</name>
<value>111111</value>
</parameter>

<!-- Class name for mm.mysql JDBC driver -->
<parameter>
<name>driverClassName</name>
<value>org.gjt.mm.mysql.Driver</value>
</parameter>

<!-- The JDBC connection url for connecting to your MySQL dB.
The autoReconnect=true argument to the url makes sure that the
mm.mysql JDBC Driver will automatically reconnect if mysqld closed the
connection. mysqld by default closes idle connections after 8 hours.
-->
<parameter>
<name>url</name>
<value>jdbc:mysql://localhost:3306/test?useUnicode=true&characterEnco ding=GBK</value>

<!--must use & not use & -->
</parameter>
</ResourceParams>
</Context>

(2)实践用例
<Context path="/tests" debug="0"
docBase="F:\WebProjects\tests"
    reloadable="true">

<Logger className="org.apache.catalina.logger.FileLogger"
      prefix="localhost_DBTest_log." suffix=".txt"
        timestamp="true"/>

<Resource name="jdbc/MysqlDB" auth="Container" type="javax.sql.DataSource"/>

        <ResourceParams name="jdbc/MysqlDB">

          <parameter>
          <name>factory</name>
         <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
          </parameter>

          <parameter>
          <name>maxActive</name>
          <value>100</value>
          </parameter>

          <parameter>
          <name>maxIdle</name>
          <value>30</value>
          </parameter>

          <parameter>
          <name>maxWait</name>
          <value>1000</value>
          </parameter>
          
          <parameter>
          <name>username</name>
          <value>root</value>
          </parameter>

          <parameter>
          <name>password</name>
          <value></value>
          </parameter>

          <parameter>
          <name>driverClassName</name>
          <value>org.gjt.mm.mysql.Driver</value>
          </parameter>

          <parameter>
          <name>url</name>
          <!—
  该部分采用IP地址,在页面解析时会报错,建议采用localhost,服务器会自动定位到本地的jsp解析服务器。在网络上其他机器上检测没有问题。
          <value>jdbc:mysql://192.168.0.65:3306/note?useUnicode=true&characterEnco ding=GBK</value>
          -->
          <value>jdbc:mysql://localhost:3306/note</value>
          </parameter>
        </ResourceParams>
    </Context>
修改发布目录下的/WEB-INF/web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<description>MySQL Test App</description>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/MysqlDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
测试用例jsp文件
<%@ page contentType="text/html;charset=GBK"%>
<%@ page import= "java.sql.* " %>
<%@ page import= "javax.naming.* "%>
<%
  try
  {
    Context initCtx = new InitialContext();
    Context ctx = (Context) initCtx.lookup("java:comp/env");
    Object obj = (Object) ctx.lookup("jdbc/MysqlDB");
    javax.sql.DataSource ds = (javax.sql.DataSource)obj;
    Connection conn = ds.getConnection();
    Statement stmt = conn.createStatement();
    String strSql = " select adduser from news ";
    ResultSet rs = stmt.executeQuery(strSql);
    while(rs.next())
    {
      out.print(rs.getString("adduser"));
      System.out.println(rs.getString("adduser"));
    }
    conn.close();

  }
  catch(Exception ex)
  {
    ex.printStackTrace();
    throw new SQLException("no");
  }
%>
数据库jdbc驱动程序文件放置位置
Tomcat中放在..\Tomcat 4\common\lib目录下。

8.Re:有没有连接池的资料,小弟最近的工作需要经常用到数据库 [Re: ysheng] Copy to clipboard
Posted by: ysheng
Posted on: 2004-04-08 11:58

但是这个java程序是专门运行在后台的,所以不用app server啊

9.Re:有没有连接池的资料,小弟最近的工作需要经常用到数据库 [Re: ysheng] Copy to clipboard
Posted by: solopro
Posted on: 2004-04-12 23:38

YDBL主要实现了数据库相关的简化程序员开发Java数据库应用程序的类库集合.包括数据库连接池,存取字符国际化等技术.

http://gro.clinux.org/projects/ydbl

10.Re:有没有连接池的资料,小弟最近的工作需要经常用到数据库 [Re: ysheng] Copy to clipboard
Posted by: zhanglixy
Posted on: 2004-04-17 20:24

用WEBLOGIC吧,连接池配置只需拖拖点点


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923