数据库连接池的配置参照 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
Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved. 闵涛 E_mail:admin@mintao.net(欢迎提供学习资源)
鄂公网安备 42011102001154号
站长:MinTao ICP备案号:鄂ICP备11006601号-18