大漠駝鈴

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

          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的規(guī)范

          Type1 用JDBC-ODBC bridge 來建立數(shù)據(jù)庫的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的驅動,部分是要依賴數(shù)據(jù)庫的客戶端,比如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:網(wǎng)絡協(xié)議驅動 這種驅動實際上是根據(jù)我們熟悉的三層結構建立的. jdbc先把對數(shù)局庫的訪問請求傳遞給網(wǎng) 絡上的中間件服務器. 中間件服務器再把請求翻譯為符合數(shù)據(jù)庫規(guī)范的調用,再把這種調用 傳給數(shù)據(jù)庫服務器.如果中間件服務器也是用java開法的,那么在在中間層也可以使用1,2型 jdbc驅動程序作為訪問數(shù)據(jù)庫的方法. 網(wǎng)絡協(xié)議驅動---------中間件服務器------------數(shù)據(jù)庫Server

          Type4 本地協(xié)議驅動
          這種驅動直接把jdbc調用轉換為符合相關數(shù)據(jù)庫系統(tǒng)規(guī)范的請求.由于4型驅動寫的應用可 以直接和數(shù)據(jù)庫服務器通訊.這種類型的驅動完全由java實現(xiàn),因此實現(xiàn)了平臺獨立性. 本地協(xié)議驅動---------數(shù)據(jù)庫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驅動做了一個說明.那么它們適合那種類型的應用開發(fā)呢?

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

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


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


          網(wǎng)站導航:
           
          主站蜘蛛池模板: 太和县| 梁山县| 静安区| 台湾省| 天镇县| 英超| 禹州市| 建德市| 神农架林区| 鹤山市| 香港| 弋阳县| 洛宁县| 改则县| 鹤庆县| 巍山| 广河县| 凤山市| 犍为县| 广南县| 南漳县| 建瓯市| 延寿县| 峨边| 阳朔县| 新昌县| 克拉玛依市| 平泉县| 乌苏市| 安庆市| 峨眉山市| 尼玛县| 湖南省| 左云县| 古田县| 赤水市| 仁布县| 永清县| 十堰市| 威远县| 江川县|