Tomcat 7 設置Oracle JNDI 
  • 事前準備
  1. Oracle JDBC Driver :放置 Tomcat 安裝的位置,例如:C:\tomcat7\lib
     (我是使用Oracle 11g Express 版本)
 setJNDI1
  • 開始設定
一開始以為網路上講修改Tomcat的xml設定檔
是在當初下載回Tomcat的安裝的位置@@"
setJNDI2      
結果原來不是.....
 
是Eclipse裡面建立的
setJNDI3 
 
我這邊設定的方式是全域的JNDI設定,有三種設定方式,
 
Step 1) 先設定Tomcat Server的server.xml
加入
<Resource name= "jdbc/oracleDB" auth ="Container"
              type= "javax.sql.DataSource"
                      factory= "org.apache.tomcat.jdbc.pool.DataSourceFactory"
                      driverClassName="oracle.jdbc.OracleDriver"
              url= "jdbc:oracle:thin:@localhost:1521:xe"
              username= "username" password ="password"
                      maxActive="20" maxIdle="10"/>
 Image4
這邊還有很多屬性可以設定,
請看 
介紹
 
我這邊首要是能建立連線就好,先隨意設個屬性可以Run成功即可。
 
Step 2) 再到此server.xml下面一點的地方找尋<Host> ... </Host>,確認裡面有你的專案名稱
我的Create的專案名稱為CDBRS2
加入
<ResourceLink global ="jdbc/oracleDB" name ="jdbc/oracleDB" type="javax.sql.DataSource"/>
 
Image5
 
===2014.10.8補充===
還有Context.xml裡面也要加入才能正常運作...
<ResourceLink global ="jdbc/oracleDB" name ="jdbc/oracleDB" type="javax.sql.DataSource"/>
 
Image  
 
Step 3) 再到Eclipse Project裡的WEB-INF/web.xml 加入
Image6 
<!-- Oracle JNDI -->
        <resource-ref>
              <description> Oracle DB</description >
               <res-ref-name> jdbc/oracleDB </res-ref-name>
               <res-type> javax.sql.DataSource</res-type >
               <res-auth> Container</res-auth >
        </resource-ref>
 
Image7
step 4) 因為我有用Springframework,所以設定springframework吃的xml檔
Image8
專案裡面設定是applicationContext.xml為空的
Image9
主要都是寫在datasource.xml
Image10
 
done~成功連線
arrow
arrow

    codingboy 發表在 痞客邦 留言(2) 人氣()