這是我在項目當中積累的資料關于配置tomcat和 weblogic的數據源,貼出來和大家分享,有什么問題還請多指教,共同學習,共同進步
          一、tomcat數據源的配制
          ★★注意將數據庫驅動程序最好放在common里,tomcat最先加載這里的驅動,放在server里有時候會出現找不到驅動程序的錯誤

           在tomcat5.5中需要下載apache-tomcat-5.5admin.tar.rar 這個包才可以進行配制
             1.首先進入tomcat的配制數據源的頁面Data Sources中配制jndi等連接信息如(jndi為hdb)
             2.在自己應用中的WEB-INF中的web.xml中添加如下:
           <resource-ref>
             <description>
               Resource reference to a factory for java.sql.Connection
               instances that may be used for talking to a particular
               database that is configured in the server.xml file.
             </description>
             <res-ref-name>
               hdb
             </res-ref-name>
             <res-type>
               javax.sql.DataSource
             </res-type>
             <res-auth>
               Container
             </res-auth>
           </resource-ref>
              3.在META-INF中添加context.xml文件內容如下:
              <?xml version="1.0" encoding="UTF-8"?>
           <Context>
             <WatchedResource>WEB-INF/web.xml</WatchedResource>
             <Resource name="hdb" auth="Container"
                type="javax.sql.DataSource" username="wangwin" password="wangwin"
                driverClassName="oracle.jdbc.driver.OracleDriver"
                url="jdbc:oracle:thin:@127.0.0.1:1521:ora9"
                maxActive="10" maxIdle="2"/>
           </Context>
             4.在程序中通過JNDI得到連接對象內容如下:
             try {
           Context initCtx = new InitialContext();
           Context envCtx = (Context) initCtx.lookup("java:comp/env");//這里這是必須的。。。
           DataSource ds = (DataSource)(envCtx.lookup( "hdb" ));
           if (ds != null){
               Connection conn = ds.getConnection();//得到連接對象測試內容
               conn.setAutoCommit(false);
               Statement stm = conn.createStatement();
               ResultSet rs = stm.executeQuery("select * from tshp_flow");
               while(rs.next()){
            System.out.println(rs.getString(1));
            System.out.println(rs.getString(2));
            System.out.println(rs.getString(3));
               }
             }else{
               }
           } catch (NamingException ex) {
            ex.printStackTrace();
           }
          二、weblogic數據源的配制
           1.打開weblogic的控制臺-服務-JDBC-連接緩沖池 配制數據庫的連接信息
           2.服務-JDBC-數據源創建JNDI-繼續-選擇剛剛配制好的數據庫JDBC
           3.得到連接對象

          posted on 2007-12-24 12:02 LifeNote 閱讀(3149) 評論(0)  編輯  收藏 所屬分類: Java 、tomcat
           
          主站蜘蛛池模板: 南澳县| 仲巴县| 龙川县| 贺州市| 蒙自县| 兖州市| 沈阳市| 安新县| 惠水县| 鄂尔多斯市| 突泉县| 东山县| 乐陵市| 旺苍县| 民丰县| 乌拉特中旗| 孟村| 增城市| 自治县| 安宁市| 电白县| 诸城市| 柘荣县| 盱眙县| 手机| 河池市| 即墨市| 隆化县| 阆中市| 蛟河市| 吉木萨尔县| 鸡西市| 竹北市| 中方县| 西乌| 巴彦淖尔市| 水城县| 乐都县| 鄱阳县| 揭东县| 博乐市|