分类:
2008-05-29 15:47:10
...
type="javax.sql.DataSource"/>
factory
org.apache.commons.dbcp.BasicDataSourceFactory
url
jdbc:mysql://localhost/GUESTBOOK
driverClassName
com.mysql.jdbc.Driver
username
caterpillar
password
123456
maxWait
3000
maxIdle
10
maxActive
100
...
...
JNDI JDBC DataSource
jdbc/GUESTBOOK
javax.sql.DataSource
Container
...
<%@page import="java.sql.*"%>
<%@ page import="javax.sql.*" %>
<%@ page import="javax.naming.*" %>
<%@page contentType="text/html;charset=big5"%>
<%
try {
Context initContext = new InitialContext();
Context envContext =
(Context)initContext.lookup("java:/comp/env");
DataSource ds =
(DataSource)envContext.lookup("jdbc/GUESTBOOK");
Connection conn = ds.getConnection();
if(!conn.isClosed())
out.println("資料庫連線測試成功!");
conn.close();
}
catch(SQLException e) {
out.println(e.toString());
}
%>