<res-ref-name>jdbc/mousie</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
用来测试的dbtest.jsp:
<%@ page import=\"javax.naming.Context\" %>
<%@ page import=\"javax.sql.DataSource\"%>
<%@ page import=\"javax.naming.InitialContext\"%>
<%@ page import=\"java.sql.*\"%>
<%
DataSource ds = null;
try{
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup(\"java:comp/env\");
ds = (DataSource)envCtx.lookup(\"jdbc/mousie\");
if(ds!=null){
out.println(\"Connection is OK!\");
Connection cn=ds.getConnection();
if(cn!=null){
out.println(\"cn is Ok!\");
Statement stmt = cn.createStatement();
ResultSet rst = stmt.executeQuery(\"select * from tophotter\");
out.println(\"<p>rst is Ok!</p>\" + rst.next());
do {
out.println(\"<P>BOOK_CODE:\" + rst.getString(\"username\"));
}
while(rst.next());
cn.close();
}
else{
out.println(\"rst Fail!\");
}
}
else
out.println(\"Fail!\");
}catch(Exception ne){ out.println(ne);
}
%>