日期:2014-05-16 浏览次数:20816 次
<Resource name="jdbc/Testcp" auth="Container" type="javax.sql.DataSource" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/bbs?autoReconnect=true" maxActive="50" maxldle="10" maxWait="5000" username="root" password="admin" />
<Context path="/Testconnpool" debug="5" reloadable="true" crossContext="true"> <ResourceLink name="jdbc/Testcp" global="jdbc/Testcp" type="javax.sql.DataSource"/> </Context>
<resource-ref> <description>DB Connection</description> <res-ref-name>jdbc/Testcp</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref>
<%@ page language="java" contentType="text/html; charset=GB18030" pageEncoding="GB18030"%> <%@ page import = "java.sql.*" %> <%@ page import = "javax.naming.*"%> <%@ page import = "javax.sql.*" %> <% DataSource ds = null; Context initCtx = new InitialContext(); ds = (DataSource)initCtx.lookup("java:comp/env/jdbc/Testcp"); Connection conn = ds.getConnection(); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("select * from article"); while(rs.next()){ out.println(rs.getString("title")+"<br>"); } rs.close(); stmt.close(); conn.close(); %>