您可以在这里快速查找:


 
您的位置: 编程学习 > java教程 > 200507
文章分类

Java技术
2005: 03 04 05 06 07 08
09 10 11 12
2006: 01 02

Asp.net
2005: 07 08 09 10 11 12
2006: 01 02

VB编程
2006: 02

Asp编程
2005: 11 12
2006: 01 02

C++/VC
2005: 10 11 12
2006: 01 02

Delphi
2005: 12
2006: 01 02

其它

 本文章适合所有读者

JBOSS3.2.5中MYSQL数据库连接池的建立与测试

pbMaster

数据库连接池的配置参照 samlei 的文档《切换JBOSS默认数据库到MySQL》 
http://dev.csdn.net/develop/article/33/33406.shtm


测试连接池的JSP页面:
<!-- Copyright (c) 2002 by ObjectLearn. All Rights Reserved. -->
<%@ page import="javax.naming.*"%>
<%@ page import="javax.sql.*"%>
<%@ page import="java.sql.*"%>

<%
    Context ctx = new InitialContext();  //得到初始化上下文

    Object obj = ctx.lookup("java:/MySqlDS");//查找连接池
    DataSource ds = (DataSource) obj;//转换成DataSource

    try {
     String temp;
      Connection connect = ds.getConnection();//从连接池中得到一个连接
      System.out.println("Success connect Mysql Connection Pool!");

      Statement stmt = connect.createStatement();
      ResultSet rs = stmt.executeQuery("select * from pet");
      while (rs.next()) {
       temp=rs.getString("name");
%>

<html>
 <head>
   <title>Welcome</title>
 </head>
 <body>
  <center>name is : <%=temp%></center>
  
 </body>
</html>
<%
      }
    }
    catch (Exception e) {
      System.out.print("get data error!");
      e.printStackTrace();
    }
%>

页面返回结果:
name is : catmiw