ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 在JBOSS中使用mysql连接池

在JBOSS中使用mysql连接池

原创 Linux操作系统 作者:season0891 时间:2009-07-02 10:02:46 0 删除 编辑
转自 网络

连接池配置:
从${JBOSS_HOME}/docs/examples/jca目录下把mysql-ds.xml拷贝到${JBOSS_HOME}/server/default/deploy下,做如下少许修改



<!-- $Id: mysql-ds.xml 63175 2007-05-21 16:26:06Z rrajesh $ -->
<!-- Datasource config for MySQL using 3.0.9 available from:
http://www.mysql.com/downloads/api-jdbc-stable.html
-->


 
    mysqlds
    jdbc:mysql://localhost:3306/discuz
    com.mysql.jdbc.Driver
    root
    123456
    org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter
    <!-- should only be used on drivers after 3.22.1 with "ping" support
    org.jboss.resource.adapter.jdbc.vendor.MySQLValidConnectionChecker
    -->
    <!-- sql to call when connection is created
    some arbitrary sql
      -->
    <!-- sql to call on an existing pooled connection when it is obtained from pool - MySQLValidConnectionChecker is preferred for newer drivers
    some arbitrary sql
      -->

    <!--最小连接池数目-->
    5

    <!--最大连接池数目-->
    800

    <!-- 数据库连接空闲时间,单位为分钟,如果负载较大,可以设为5,如果一般,可以设为3 -->
    5

    <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml -->
   
       mysql
   

 



JBoss测试JSP :

<%@ page contentType="text/html;charset=utf-8"
         import="java.io.*,java.util.*,java.sql.*,javax.sql.*,javax.naming.*"%>
        

   
        <br>            jboss 连接池测试<br>       
   
   
       


            test
           

            连接池:
       


        <%
            try {
                Context ctx = new javax.naming.InitialContext();
                DataSource ds = (DataSource) ctx.lookup("java:mysqlds");


                Connection conn = ds.getConnection();
                Statement stmt = conn.createStatement();
                ResultSet rs = stmt.executeQuery("select * from cdb_members");
                while (rs.next()) {
                    out.print("
\n" + rs.getString(2));

                }
                out.print("
Successful!成功!!\n");
                rs.close();
                stmt.close();
                conn.close();
            } catch (Exception e) {
                out.print("出现意外!" + e.getMessage());
                e.printStackTrace();
            }
       
        %>
       
   

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/90618/viewspace-608121/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2008-06-10

  • 博文量
    791
  • 访问量
    1926442