• web开发连接池方法


    1myeclipse+resin服务器

    当项目使用了sevlet时需将resin服务器的配置文件resin.conf中的<host></host>标签中的<web-app id="/" document-directory="webapps/webproj"/> 红色字体的为项目名称,默认是ROOT

    2myeclipse+tomcat服务器mysql数据库连接方式(连接池)
    第1种方式:修改tomcat的context.xml和web.xml文件:ontext.xml在<context></context>之间添加连接池如下:<Resource name="jdbc/mysql" auth="Container" type="javax.sql.DataSource" maxActive="50" maxIdle="10"  maxWait="5000"  username="你的mysql用户" password="你的mysql密码" driverClassName="org.gjt.mm.mysql.Driver" url="jdbc:mysql://localhost/jyw" />红色字体是数据库名称web.xml中的<web-app></web-app>之间加入:
    1 <resource-ref>
    2        <description>DB Connection</description>
    3        <res-ref-name>jdbc/mysql</res-ref-name>
    4        <res-type>javax.sql.DataSource</res-type>
    5        <res-auth>Container</res-auth>
    6     </resource-ref>
    注意的地方: context.xml文件中的name="jdbc/mysql"要和web.xml中的<res-ref-name>jdbc/mysql</res-ref-name>要一致;
    mysql 的jdbc驱动“mysql-connector-java-5.0.2-beta-bin.jar”复制到配置tomcat下的lib目录
    第2种方式:
    tomcat的配置文件 context.xml的<context></context>标签之间添加:
    1 <ResourceLink name="jdbc/DBPool" type="javax.sql.DataSource" global="jdbc/DBPool"/>

    在server.xml文件的<GlobalNamingResources> </GlobalNamingResources>标签之间添加:
    <Resource name="jdbc/DBPool" type="javax.sql.DataSource" password="123456"
                   driverClassName="com.mysql.jdbc.Driver" maxIdle="2"
                   maxWait="5000"  username="root"
                   url="jdbc:mysql://127.0.0.1:3306/resourcesdb" maxActive="4"/>
    在web.xml文件的<web-app></web-app>标签之间添加:
    <resource-ref>
         <description>DB Connection</description>
           <res-ref-name>jdbc/DBPool</res-ref-name>
           <res-type>javax.sql.DataSource</res-type>
           <res-auth>Container</res-auth>
       </resource-ref>
    编程过程需要用到的java(连接池DBPool)文件
    调用方法的语句: Connection conn = DBPool.getPool().getConnection();

    需要更改tomcat的虚拟目录是在server.xml文件的<host></host>标签之间添加:
    <Context   path=""   docBase="D:myeclipseworkspacejyw"  reloadable="true"   debug="0">
       </Context>

    一分辛苦一分才
  • 相关阅读:
    Django-models,继承AbstractUser类
    Django-views,用户认证,login_requierd()
    django前篇
    jquery插件
    jquery事件及插件
    jquery操作元素
    jquery选择器筛选器
    js作用域与作用域链
    js之DOM(二)
    bootstrap
  • 原文地址:https://www.cnblogs.com/JoanLin-workNotes/p/3751901.html
Copyright © 2020-2023  润新知