| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 741 人关注过本帖
标题:谁能教我怎样用连接池连接数据库
只看楼主 加入收藏
nibuhaoma
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2010-3-29
结帖率:83.33%
收藏
 问题点数:0 回复次数:5 
谁能教我怎样用连接池连接数据库
我用过连接池连接数据库,连接池在服务器server.xml
配置好的,自己写了连接程序,但是在JSP应用当中,就出现错误了,我烦死了,请问熟悉这方面的认识教教我,我在一个JSP网站呢,比较急,在次先谢了,最好给我一个好的程序参考,至于分,我现在没有了,下次在给你们,拜托了!!!!
搜索更多相关主题的帖子: 数据库 
2010-06-12 19:29
zhiliangwang
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2010-6-29
收藏
得分:0 
连接的是什么数据库啊
2010-06-29 17:42
午夜屠猪男
Rank: 4
等 级:业余侠客
威 望:2
帖 子:194
专家分:259
注 册:2007-1-3
收藏
得分:0 
proxool.xml

<?xml version="1.0" encoding="UTF-8"?>
<something-else-entirely>
  <proxool>
    <alias>proMysql</alias>
    <driver-url>jdbc:mysql://mysqlhost:3306/heating?autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=UTF8&amp;zeroDateTimeBehavior=convertToNull</driver-url>
    <driver-class>org.gjt.mm.mysql.Driver</driver-class>
    <driver-properties>
      <property name="user" value="root"/>
      <property name="password" value=""/>
    </driver-properties>
    <maximum-connection-count>10</maximum-connection-count>
    <minimum-connection-count>5</minimum-connection-count>
    <house-keeping-sleep-time>90000</house-keeping-sleep-time>
    <prototype-count>5</prototype-count>
    <test-before-use>true</test-before-use>
    <simultaneous-build-throttle>5</simultaneous-build-throttle>
    <house-keeping-test-sql>SELECT CURRENT_DATE</house-keeping-test-sql>
  </proxool>
 
</something-else-entirely>

app-config-context.xml


    <bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName">
            <value>org.logicalcobwebs.proxool.ProxoolDriver</value>
        </property>
        <property name="url">
            <value>proxool.proMysql</value>
        </property>
    </bean>


监听器

public class ProxoolListener implements ServletContextListener {
    private static final Log LOG = LogFactory.getLog(ProxoolListener.class);

    private static final String XML_FILE_PROPERTY = "xmlFile";

    private static final String PROPERTY_FILE_PROPERTY = "propertyFile";

    private static final String AUTO_SHUTDOWN_PROPERTY = "autoShutdown";

    @SuppressWarnings("unused")
    private boolean autoShutdown = true;

    public void contextDestroyed(ServletContextEvent arg0) {
        System.out.println("destroy database pool....");
    }

    public void contextInitialized(ServletContextEvent contextEvent) {
        System.out.println("proxool Initializing...");
        ServletContext context = contextEvent.getServletContext(); //

2010-06-30 11:07
午夜屠猪男
Rank: 4
等 级:业余侠客
威 望:2
帖 子:194
专家分:259
注 册:2007-1-3
收藏
得分:0 
String appDir = contextEvent.getServletContext().getRealPath("/");
        Properties properties = new Properties();

        Enumeration names = context.getInitParameterNames();
        while (names.hasMoreElements()) {
            String name = (String) names.nextElement();
            String value = context.getInitParameter(name);

            if (name.equals(XML_FILE_PROPERTY)) {
                try {
                    File file = new File(value);
                    if (file.isAbsolute()) {
                        JAXPConfigurator.configure(value, false);
                    } else {
                        JAXPConfigurator.configure(appDir + File.separator + value, false);
                    }
                } catch (ProxoolException e) {
                    LOG.error("Problem configuring " + value, e);
                }
            } else if (name.equals(PROPERTY_FILE_PROPERTY)) {
                try {
                    File file = new File(value);
                    if (file.isAbsolute()) {
                        PropertyConfigurator.configure(value);
                    } else {
                        PropertyConfigurator.configure(appDir + File.separator + value);
                    }
                } catch (ProxoolException e) {
                    LOG.error("Problem configuring " + value, e);
                }
            } else if (name.equals(AUTO_SHUTDOWN_PROPERTY)) {
                autoShutdown = Boolean.valueOf(value).booleanValue();
            } else if (name.startsWith("jdbc")) { //

2010-06-30 11:09
午夜屠猪男
Rank: 4
等 级:业余侠客
威 望:2
帖 子:194
专家分:259
注 册:2007-1-3
收藏
得分:0 
照着做。我正用着呢

2010-06-30 11:09
nibuhaoma
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2010-3-29
收藏
得分:0 
回复 5楼 午夜屠猪男
成功了,谢谢,以后多多交流!!!!
2010-07-02 19:06
快速回复:谁能教我怎样用连接池连接数据库
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017461 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved