sp; is exceeded. Set to -1 to wait indefinitely.--> <parameter> <name>maxWait</name> <value>10000</value> </parameter> </ResourceParams> </Context> 这样就算连接完了3)测试: DATABASE_NAME:testdb APPLICATION_NAME:mysqlTest 在testdb数据库里新建表userinfo id | username 1 aaa 2 bbb 4)web.xml <web-app>
<resource-ref> <description>MySQL Datasource example</description> <res-ref-name>jdbc/testdb</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref>
</web-app>
5)index.jsp <%@ page contentType="text/html;charset=gb2312" language="java" import="java.sql.*,javax.naming.*"%> <% Context initCtx = new InitialContext(); Context ctx = (Context) initCtx.lookup("java:comp/env"); Object obj = (Object) ctx.lookup("jdbc/testdb"); javax.sql.DataSource ds = (javax.sql.DataSource)obj; Connection conn = ds.getConnection(); Statement stmt = conn.createStatement(); String strSql = "select * from userinfo"; ResultSet rs = stmt.executeQuery(strSql);%> <body> <%while(rs.next()){%> <p> <%=rs.getString("username")%> </p> <%}%> <body> 可以看到输出结果为: aaa bbb
上一页 [1] [2] |