zoukankan      html  css  js  c++  java
  • Tomcat数据库连接池配置

    这里以MySQL为例:

    首先是conf目录下的server.xml

    GlobalNamingResources中添加:

        <Resource
          name="java/mysql"
          type="javax.sql.DataSource"
          password=""
          driverClassName="com.mysql.jdbc.Driver"
          maxIdle="2"
          maxWait="5000"
          username="root"
          url="jdbc:mysql://127.0.0.1:3306/edoas2"
          maxActive="20"/>

    在content.xml中添加:

    <ResourceLink
       name="java/mysql"
       type="javax.sql.DataSource"
       global="java/mysql"/>

    在所在应用中的web.xml中添加:

       <resource-ref>
        <description>MySQL DB Connection Pool</description>
        <res-ref-name>java/mysql</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
        <res-sharing-scope>Shareable</res-sharing-scope>
       </resource-ref>

    注意保持黑体部分的一致性,这样在程序中就可以使用了:

         out.print("DB Test Start......<br>");
        
         DataSource ds=null;
        
         try{
        
         InitialContext ctx=new InitialContext();
        
         ds=(DataSource)ctx.lookup("java:comp/env/java/mysql");
        
         Connection conn=ds.getConnection();
         conn.close();
         out.print("DB Test Success......");
        
         }catch(Exception ex){
         
          out.print("DB Test hava a Error....."+ex.getMessage());
          ex.printStackTrace();
        
         }

  • 相关阅读:
    git 拉取远程代码 git branch -vv --all
    常用命令统计
    topology key
    gstreamer 相关直播源(rtmp rtsp)
    汉诺塔问题 最简单的图文讲解递归实现
    RTP 用ffmpeg
    kurento + nodejs 开源项目 webRTC 转成 RTMP输出
    RTP SDP 详解 RTCP 附带说了一下SRTP RTSP
    RxSwiftCommunity/Action使用介绍
    zsh Shell 增加自动补全、语法高亮
  • 原文地址:https://www.cnblogs.com/macula7/p/1960479.html
Copyright © 2011-2022 走看看