大漠駝鈴

          置身浩瀚的沙漠,方向最為重要,希望此blog能向大漠駝鈴一樣,給我方向和指引。
          Java,Php,Shell,Python,服務器運維,大數據,SEO, 網站開發、運維,云服務技術支持,IM服務供應商, FreeSwitch搭建,技術支持等. 技術討論QQ群:428622099
          隨筆 - 238, 文章 - 3, 評論 - 117, 引用 - 0
          數據加載中……

          jdbc 中四種type解釋 轉載

          There are many possible implementations of JDBC drivers. These implementations
          are categorized as follows:
          n Type 1 — drivers that implement the JDBC API as a mapping to another data
          access API, such as ODBC. Drivers of this type are generally dependent on a
          native library, which limits their portability. The JDBC-ODBC Bridge driver is an
          example of a Type 1 driver.
          n Type 2 — drivers that are written partly in the Java programming language and
          partly in native code. These drivers use a native client library specific to the data
          source to which they connect. Again, because of the native code, their portability
          is limited.
          n Type 3 — drivers that use a pure Java client and communicate with a middleware
          server using a database-independent protocol. The middleware server then
          communicates the client’s requests to the data source.
          n Type 4 — drivers that are pure Java and implement the network protocol for a
          specific data source. The client connects directly to the data source.


          以上來自JDBC3.0的規范

          Type1 用JDBC-ODBC bridge 來建立數據庫的connection,這種效率很一般,

                     

           public static Connection getConnectionbyBridge() {
            Connection conn = null;
            try {
             Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
             conn = DriverManager.getConnection("jdbc:odbc:abc", "cms", "cms");
             System.out.println(conn.getTransactionIsolation());

            } catch (ClassNotFoundException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
            } catch (SQLException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
            }

            return conn;
           }

          Typ2 是效率比較高的,部分用了jdbc的驅動,部分是要依賴數據庫的客戶端,比如ORACLE 10g OCI

           public static Connection getConnectionOCI() {
            Connection conn = null;
            try {
             Class.forName("oracle.jdbc.driver.OracleDriver");
             conn = DriverManager.getConnection(
               "jdbc:oracle:oci:@127.0.0.1:1521:orcl", "cms", "cms");
             
             System.out.println(conn.getAutoCommit());

            } catch (ClassNotFoundException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
            } catch (SQLException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
            }

            return conn;
           }



          Type3:網絡協議驅動 這種驅動實際上是根據我們熟悉的三層結構建立的. jdbc先把對數局庫的訪問請求傳遞給網 絡上的中間件服務器. 中間件服務器再把請求翻譯為符合數據庫規范的調用,再把這種調用 傳給數據庫服務器.如果中間件服務器也是用java開法的,那么在在中間層也可以使用1,2型 jdbc驅動程序作為訪問數據庫的方法. 網絡協議驅動---------中間件服務器------------數據庫Server

          Type4 本地協議驅動
          這種驅動直接把jdbc調用轉換為符合相關數據庫系統規范的請求.由于4型驅動寫的應用可 以直接和數據庫服務器通訊.這種類型的驅動完全由java實現,因此實現了平臺獨立性. 本地協議驅動---------數據庫Server

           public static Connection getConnection() {
            Connection conn = null;
            try {
             Class.forName("oracle.jdbc.driver.OracleDriver");
             conn = DriverManager.getConnection(
               "jdbc:oracle:thin:@127.0.0.1:1521:orcl", "cms", "cms");
             
             System.out.println(conn.getAutoCommit());

            } catch (ClassNotFoundException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
            } catch (SQLException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
            }

            return conn;
           }
           

          對四種類型的jdbc驅動做了一個說明.那么它們適合那種類型的應用開發呢?

          Jdbc-odbc橋由于它的執行效率不高,更適合做為開發應用時的一種過度方案,或著對于初學 者了解jdbc編程也較適用. 對于那些需要大數據量操作的應用程序則應該考慮2,3,4型驅動.在intranet方面的應用可以 考慮2型驅動,而且目前開發 的趨勢是使用純java.所以3,4型驅動也可以作為考慮對象. 至于基于internet方面的應用就只有考慮3,4型驅動了. 因為3型驅動可以把多種數據庫驅 動都配置在中間層服務器.所以3型驅動最適合那種需要同時連接多個不同種類的數據庫, 并且對并發連接要求高的應用. 4型驅動則適合那些連接單一數據庫的工作組應用。
          但是Typ2 和type1我認為很少會用到,type1 可移植,效率都不行,type2效率雖然高,但是可移植太差,只有3.4是最常用的,當然大規模的分布式應用3是很好的選擇,一般的企業應用,我認為用4就很夠了,并且效率也高。

          posted on 2009-03-06 09:41 草原上的駱駝 閱讀(451) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 天长市| 泰安市| 奈曼旗| 临潭县| 加查县| 盈江县| 岑溪市| 台安县| 惠来县| 革吉县| 衡水市| 通河县| 长沙市| 广东省| 武定县| 洛扎县| 新河县| 武安市| 丰台区| 广平县| 新沂市| 报价| 隆德县| 天全县| 惠安县| 盖州市| 谢通门县| 汉川市| 沧源| 盐亭县| 溧水县| 布拖县| 建德市| 宁河县| 衡阳县| 六盘水市| 克什克腾旗| 肥乡县| 延津县| 清水县| 平泉县|