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();
?
%>
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
