Tomcat 5.5 和 tomcat5.0 的配置是不一样的 ,Tomcat5.5 的配置如下 :
在 server.xml 文件中配置如下 :
<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>
在 C:\Tomcat 5.5\common\lib 目录下拷入 class12.jar
class12.jar 是 oracle 的 jdbc 的驱动程序不包
在 web.xml 中修改代码
<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();
%>