H
hooyu
Unregistered / Unconfirmed
GUEST, unregistred user!
1.JSP
<%@ page contentType="text/html;
charset=GBK" %>;
<%@ page import="java.sql.*" %>;
<%@ page import="javax.naming.Context" %>;
<%@ page import="javax.naming.InitialContext" %>;
<%@ page import="javax.sql.DataSource" %>;
<html>
<head>
<title>
测试数据源连接(或Pool数据池化)
</title>
</head>
<body bgcolor="#ffffff">
<h1>
测试数据源连接(或Pool数据池化)
</h1>
<Table>
<%
Connection conn = null;
try {
Context ctx = (Context) new InitialContext().
lookup("java:comp/env");
conn = ((DataSource) ctx.lookup("jdbc/homemaking")).
getConnection();
}
catch (Exception e) {
System.out.println("ABC");}
try {
Statement ps = conn.createStatement();
ResultSet rs = ps.executeQuery("select * from sysobjects");
while (rs.next()) {
System.out.println("<TR><TD>"+rs.getString(1)+"</TD></TR>");
}
}
catch (Exception e) {
System.out.println("ABC");}
%>
</Table>
</body>
</html>
<%@ page contentType="text/html;
charset=GBK" %>;
<%@ page import="java.sql.*" %>;
<%@ page import="javax.naming.Context" %>;
<%@ page import="javax.naming.InitialContext" %>;
<%@ page import="javax.sql.DataSource" %>;
<html>
<head>
<title>
测试数据源连接(或Pool数据池化)
</title>
</head>
<body bgcolor="#ffffff">
<h1>
测试数据源连接(或Pool数据池化)
</h1>
<Table>
<%
Connection conn = null;
try {
Context ctx = (Context) new InitialContext().
lookup("java:comp/env");
conn = ((DataSource) ctx.lookup("jdbc/homemaking")).
getConnection();
}
catch (Exception e) {
System.out.println("ABC");}
try {
Statement ps = conn.createStatement();
ResultSet rs = ps.executeQuery("select * from sysobjects");
while (rs.next()) {
System.out.println("<TR><TD>"+rs.getString(1)+"</TD></TR>");
}
}
catch (Exception e) {
System.out.println("ABC");}
%>
</Table>
</body>
</html>