【正文】
More recently, Microsoft has introduced new APIs beyond ODBC: RDO, ADO, DAO, and OLE DB. These designs move in the same direction as JDBC in many ways, for example, in being objectoriented interfaces to databases based on classes that can be implemented on ODBC. However, we did not see functionality in any of these interfaces pelling enough to make them an alternative basis to ODBC, especially with the ODBC driver market wellestablished. Mostly they represent a thin veneer on ODBC. This is not to say that JDBC does not need to evolve from the initial release described in this book。. More sophisticated mappings are also provided, for example, where rows of multiple tables are bined in a Java class. As interest in JDBC has grown, more developers have been working on JDBCbased tools to make building programs easier, as well. Programmers have also been writing applications that make accessing a database easier for the end user. For example, an application might present a menu of database tasks from which to choose. After a task is selected, the application presents prompts and blanks for filling in information needed to carry out the selected task. With the requested input typed in, the application then automatically invokes the necessary SQL mands. With the help of such an application, users can perform database tasks even when they have little or no knowledge of SQL syntax. JDBC versus ODBC and other APIs At this point, Microsoft39。39。 Statement stmt = ()。對(duì)第 2 類(lèi)驅(qū)動(dòng)程序可能會(huì)有一些變種,這些變種要求有連接器,但通常這些是更加不可取的解決方案。有可能所有這種解決方案的提供者都提供適合于 Intra 用的產(chǎn)品。注意,必須將 ODBC 二進(jìn)制代碼(許多情況下還包括數(shù)據(jù)庫(kù)客戶機(jī)代碼)加載到使用該驅(qū)動(dòng)程序的每個(gè)客戶機(jī)上。 “符合 JDBC 標(biāo)準(zhǔn) TM” 表示提供者的 JDBC 實(shí)現(xiàn)已經(jīng)通過(guò)了 JavaSoft 提供的一致性測(cè)試。例如,對(duì)日期文字和已儲(chǔ)存過(guò)程的調(diào)用都有轉(zhuǎn)義語(yǔ)法。人們希望 SQL 中真正標(biāo)準(zhǔn)的那部份能夠進(jìn)行擴(kuò)展以包括越來(lái)越多的功能 。最后,許多情況下三層結(jié)構(gòu)可提供一些性能上的好處。用戶的 SQL 語(yǔ)句被送往數(shù)據(jù)庫(kù)中,而其結(jié)果將被送回給用戶。 最近, Microsoft 又引進(jìn)了 ODBC 之外的新 API: RDO、 ADO 和 OLE DB。 ? 啟用“純 Java ”機(jī)制需要象 JDBC 這樣的 Java API。現(xiàn)在的問(wèn)題已變成: “為什么需要 JDBC”? 回答如下: ? ODBC 不適合直接在 Java 中使用,因?yàn)樗褂? C 語(yǔ)言接口。程序員也一直在編寫(xiě)力圖使最終用戶對(duì)數(shù)據(jù)庫(kù)的訪問(wèn)變得更為簡(jiǎn)單的應(yīng)用程序。例如,可在 SQL 語(yǔ)句中使用 Java 變量,用以接受或提供 SQL 值。 } ? JDBC 是一種低級(jí) API ,是高級(jí) API 的基礎(chǔ) JDBC 是個(gè)“低級(jí)”接口,也就是說(shuō),它用于直接調(diào)用 SQL 命令。對(duì)于商務(wù)上的銷(xiāo)售信息服務(wù), Java 和 JDBC 可為外部客戶提供獲取信息更新的更好方法。例如,用 Java 和 JDBC API 可以發(fā)布含有 applet 的網(wǎng)頁(yè),而該 applet 使用的信息可能來(lái)自遠(yuǎn)程數(shù)據(jù)庫(kù)。換言之,有了 JDBC API, 就不必為訪問(wèn) Sybase 數(shù)據(jù)庫(kù)專(zhuān)門(mén)寫(xiě)一個(gè)程序,為訪問(wèn) Oracle 數(shù)據(jù)庫(kù)又專(zhuān)門(mén)寫(xiě)一個(gè)程序,為訪問(wèn) Informix 數(shù)據(jù)庫(kù) 又寫(xiě)另一個(gè)程序,等等。 有了 JDBC,向各種關(guān)系數(shù)據(jù)庫(kù)發(fā)送 SQL 語(yǔ)句就是一件很容易的事。 JDBC 擴(kuò)展了 Java 的功能。程序員可只編寫(xiě)一遍應(yīng)用程序或只更新一次,然后將它放到服務(wù)器上,隨后任何人就都可得到最新版本的應(yīng)用程序。 float f = getFloat(c)。相反,嵌入式 SQL 預(yù)處理器允許程序員將 SQL 語(yǔ)句直接與 Java 混在一起使用。 隨著人們對(duì) JDBC 的興趣日益增漲,越來(lái)越多的開(kāi)發(fā)人員一直在使用基于 JDBC 的工具,以使程序的編寫(xiě)更加容易。為什么 Java 不使用 ODBC? 對(duì)這個(gè)問(wèn)題的回答是: Java 可以使用 ODBC,但最好是在 JDBC 的幫助下以JDBCODBC 橋的形式使用。相反, JDBC 盡量保證簡(jiǎn)單功能的簡(jiǎn)便性,而同時(shí)在必要時(shí)允許使用高級(jí)功能。它們之間最大的區(qū)別在于: JDBC以 Java 風(fēng)格與優(yōu)點(diǎn)為基礎(chǔ)并進(jìn)行優(yōu)化,因此更加易于使用。這將需要一個(gè) JDBC 驅(qū)動(dòng) 程序 來(lái)與所訪問(wèn)的特定數(shù)據(jù)庫(kù)管理系統(tǒng)進(jìn)行通訊。中間層的另一個(gè)好處是,用戶可以利用易于使用的高級(jí) API,而中間層將把它轉(zhuǎn)換為相應(yīng)的低級(jí)調(diào)用。例如,并非所有的數(shù)據(jù)庫(kù)都支持儲(chǔ)存程序或外部連接,那些支持這一功能的數(shù)據(jù)庫(kù)又相互不一致。 轉(zhuǎn)義語(yǔ)法為幾個(gè)常見(jiàn)的 SQL 分歧提供了一種標(biāo)準(zhǔn)的 JDBC 語(yǔ)法。驅(qū)動(dòng)程序開(kāi)發(fā)人員可用 JDBC API 所帶的測(cè)試工具包來(lái)確定他們的驅(qū)動(dòng)程序是否符合這些標(biāo)準(zhǔn)。因此,有關(guān)最新的信息,請(qǐng)查閱 JDBC 的網(wǎng)站,可通過(guò)從以下 URL 開(kāi)始 瀏覽找到: ? JDBC 驅(qū)動(dòng)程序的類(lèi)型 我們目前所知曉的 JDBC 驅(qū)動(dòng)程序可分為以下四個(gè)種類(lèi): JDBCODBC 橋加 ODBC 驅(qū)動(dòng)程序: JavaSoft 橋產(chǎn)品利用 ODBC 驅(qū)動(dòng)程序提供 JDBC 訪問(wèn)。通常,這是最為靈活的 JDBC 驅(qū)動(dòng)程序。第 2 類(lèi)驅(qū)動(dòng)程序在直接的純 Java 驅(qū)動(dòng)程序還沒(méi)有上市前將會(huì)作為過(guò)渡方案來(lái)使用。t have to worry about writing different applications to run on different platforms. The bination of Java and JDBC lets a programmer write it once and run it anywhere. Java, being robust, secure, easy to use, easy to understand, and automatically downloadable on a work, is an excellent language basis for database applications. What is needed is a way for Java applications to talk to a variety of different databases. JDBC is the mechanism for doing this. JDBC extends what can be done in Java. For example, with Java and the JDBC API, it is possible to publish a web page containing an applet that uses information obtained from a remote database. Or an enterprise can use JDBC to connect all its employees (even if they are using a conglomeration of Windows, Macintosh, and UNIX machines) to one or more internal databases via an intra. With more and more programmers using the Java programming language, the need for easy database access from Java is continuing to grow. MIS managers like the bination of Java and JDBC because it makes disseminating information easy and economical. Businesses can continue to use their installed databases and access information easily even if it is stored on different database management systems. Development time for new applications is short. Installation and version control are greatly simplified. A programmer can write an application or an update once, put it on the server, and everybody has access to the latest version. An