Tomcat 5.5和tomcat5.0的配置是不一样的,Tomcat5.5的配置如下:
<Context path="/Recommend" reloadable="true" docBase="C:\eclipse\workspace\Recommend" workDir="C:\eclipse\workspace\Recommend\work">
<Resource name="jdbc/myoracle" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="spstest" password="sps0922"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@192.168.6.15:1521:ora9"/>
</Context>
class12.jar是oracle的jdbc的驱动程序不包
<description>oralceDB</description>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/myoracle</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<%@ page import="javax.naming.Context" %>
<%@ page import="javax.sql.DataSource"%>
<%@ page import="javax.naming.InitialContext"%>
<%@ page import="java.sql.*"%>
<%
DataSource ds = null;
Context jndiCntx = new InitialContext();
ds =(DataSource)jndiCntx.lookup( "java:comp/env/jdbc/myoracle");
if(ds!=null){
System.out.println("Connection is OK!");
}
else
{
System.out.println("Connection is fail!");
}
Connection cn=ds.getConnection();
if(cn!=null){
System.out.println("cn is Ok!");
}
else
{
System.out.println("cn is fail!");
}
// Statement stmt = cn.createStatement();
// ResultSet rst = stmt.executeQuery("select * from BOOK");
// out.println("<p>rst is Ok!" + rst.next());
// while(rst.next()){
// System.out.println("<P>BOOK_CODE:" + rst.getString(1));
// }
cn.close();
%>