這是我在項(xiàng)目當(dāng)中積累的資料關(guān)于配置tomcat和 weblogic的數(shù)據(jù)源,貼出來和大家分享,有什么問題還請(qǐng)多指教,共同學(xué)習(xí),共同進(jìn)步
          一、tomcat數(shù)據(jù)源的配制
          ★★注意將數(shù)據(jù)庫驅(qū)動(dòng)程序最好放在common里,tomcat最先加載這里的驅(qū)動(dòng),放在server里有時(shí)候會(huì)出現(xiàn)找不到驅(qū)動(dòng)程序的錯(cuò)誤

           在tomcat5.5中需要下載apache-tomcat-5.5admin.tar.rar 這個(gè)包才可以進(jìn)行配制
             1.首先進(jìn)入tomcat的配制數(shù)據(jù)源的頁面Data Sources中配制jndi等連接信息如(jndi為hdb)
             2.在自己應(yīng)用中的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文件內(nèi)容如下:
              <?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得到連接對(duì)象內(nèi)容如下:
             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();//得到連接對(duì)象測(cè)試內(nèi)容
               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數(shù)據(jù)源的配制
           1.打開weblogic的控制臺(tái)-服務(wù)-JDBC-連接緩沖池 配制數(shù)據(jù)庫的連接信息
           2.服務(wù)-JDBC-數(shù)據(jù)源創(chuàng)建JNDI-繼續(xù)-選擇剛剛配制好的數(shù)據(jù)庫JDBC
           3.得到連接對(duì)象

          posted on 2007-12-24 12:02 LifeNote 閱讀(3145) 評(píng)論(0)  編輯  收藏 所屬分類: Javatomcat
           
          主站蜘蛛池模板: 江油市| 酉阳| 交城县| 开鲁县| 疏附县| 温宿县| 包头市| 乐亭县| 涞源县| 长春市| 康保县| 山阳县| 澄城县| 崇左市| 宝丰县| 东海县| 沙雅县| 麻城市| 和林格尔县| 义马市| 宜兰市| 孝感市| 汪清县| 平塘县| 无为县| 两当县| 西乌珠穆沁旗| 余姚市| 永胜县| 育儿| 登封市| 贵阳市| 乌鲁木齐市| 遂昌县| 洞头县| 昔阳县| 勃利县| 马鞍山市| 曲周县| 连山| 固原市|