conf下的context.
xml文件:
<Context>
<ResourceLink global="jdbc/mysql" name="jdbc/mysql" type="javax.sql.DataSource"/>
<ResourceLink global="jdbc/mssql" name="jdbc/mssql" type="javax.sql.DataSource"/>
</Context>
测试程序一(测试MSSQL连接池)
程序代码
<%@ page contentType="text/html; charset=GBK"%>
<%@ page import="java.sql.*"%>
<%@ page import="javax.sql.*"%>
<%@ page import="javax.naming.*"%>
<%
Connection con=null;
Statement sm=null;
ResultSet rs=null;
try{
InitialContext ctx=new InitialContext();
DataSource ds=(DataSource)ctx.lookup("java:comp/env/jdbc/mssql");
con = ds.getConnection();
sm = con.createStatement();
rs = sm.executeQuery("select * from users");
while(rs.next()) {%>
<%=rs.getString(1)%>
<%=rs.getString(2)%>
<br />
<%}
}catch(Exception e){
System.out.println(e.getMessage());
}finally {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {}
rs = null;
}
if (sm != null) {
try {
sm.close();
} catch (SQLException e) {}
sm = null;
}
if (con != null) {
try {
con.close();
} catch (SQLException e) {}
con = null;
}
}
%>
show the list;
测试程序二(测试MYSQL连接池)
程序代码
<%@ page contentType="text/html; charset=GBK"%>
<%@ page import="java.sql.*"%>
<%@ page import="javax.sql.*"%>
<%@ page import="javax.naming.*"%>
<%
Connection con=null;
Statement sm=null;
ResultSet rs=null;
try{
InitialContext ctx=new InitialContext();
DataSource ds=(DataSource)ctx.lookup("java:comp/env/jdbc/mysql");
con = ds.getConnection();
sm = con.createStatement();
rs = sm.executeQuery("select * from users");
while(rs.next()) {%>
<%=rs.getString(1)%>
<%=rs.getString(2)%>
<br />
<%}
}catch(Exception e){
System.out.println(e.getMessage());
}finally {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {}
rs = null;
}
if (sm != null) {
try {
sm.close();
} catch (SQLException e) {}
sm = null;
}
if (con != null) {
try {
con.close();
} catch (SQLException e) {}
con = null;
}
}
%>
show the list;
<Context>
<ResourceLink global="jdbc/mysql" name="jdbc/mysql" type="javax.sql.DataSource"/>
<ResourceLink global="jdbc/mssql" name="jdbc/mssql" type="javax.sql.DataSource"/>
</Context>
测试程序一(测试MSSQL连接池)
![程序代码](https://i-blog.csdnimg.cn/blog_migrate/46090f14d223b67b675f9ce652d025a5.png)
<%@ page contentType="text/html; charset=GBK"%>
<%@ page import="java.sql.*"%>
<%@ page import="javax.sql.*"%>
<%@ page import="javax.naming.*"%>
<%
Connection con=null;
Statement sm=null;
ResultSet rs=null;
try{
InitialContext ctx=new InitialContext();
DataSource ds=(DataSource)ctx.lookup("java:comp/env/jdbc/mssql");
con = ds.getConnection();
sm = con.createStatement();
rs = sm.executeQuery("select * from users");
while(rs.next()) {%>
<%=rs.getString(1)%>
<%=rs.getString(2)%>
<br />
<%}
}catch(Exception e){
System.out.println(e.getMessage());
}finally {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {}
rs = null;
}
if (sm != null) {
try {
sm.close();
} catch (SQLException e) {}
sm = null;
}
if (con != null) {
try {
con.close();
} catch (SQLException e) {}
con = null;
}
}
%>
show the list;
测试程序二(测试MYSQL连接池)
![程序代码](https://i-blog.csdnimg.cn/blog_migrate/46090f14d223b67b675f9ce652d025a5.png)
<%@ page contentType="text/html; charset=GBK"%>
<%@ page import="java.sql.*"%>
<%@ page import="javax.sql.*"%>
<%@ page import="javax.naming.*"%>
<%
Connection con=null;
Statement sm=null;
ResultSet rs=null;
try{
InitialContext ctx=new InitialContext();
DataSource ds=(DataSource)ctx.lookup("java:comp/env/jdbc/mysql");
con = ds.getConnection();
sm = con.createStatement();
rs = sm.executeQuery("select * from users");
while(rs.next()) {%>
<%=rs.getString(1)%>
<%=rs.getString(2)%>
<br />
<%}
}catch(Exception e){
System.out.println(e.getMessage());
}finally {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {}
rs = null;
}
if (sm != null) {
try {
sm.close();
} catch (SQLException e) {}
sm = null;
}
if (con != null) {
try {
con.close();
} catch (SQLException e) {}
con = null;
}
}
%>
show the list;