`
桔红糕
  • 浏览: 42521 次
  • 性别: Icon_minigender_2
  • 来自: 上海
社区版块
存档分类
最新评论

JDBC tutorial from SUN(一)

阅读更多
JDBC(TM) Database Access: Table of Contents

1.JDBC Introduction

The JDBC API is a Java API that can access any kind of tabular data, especially data stored in a Relational Database.
(“任何表单数据,特别是关系型数据”他想说明什么?它也支持非关系型数据库咯)

JDBC helps you to write java applications that manage these three programming activities:
(3步,连接数据源,发送查询或修改请求,获取并处理请求结果。谁谁谁说有6大步,今天又看到3个步骤。嘿嘿)
Connect to a data source, like a database
Send queries and update statements to the database
Retrieve and process the results received from the database in answer to your query

The following simple code fragment gives a simple example of these three steps:

Connection con = DriverManager.getConnection
           ( "jdbc:myDriver:wombat", "myLogin","myPassword");
			  
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM Table1");
while (rs.next()) {
	int x = rs.getInt("a");
	String s = rs.getString("b");
	float f = rs.getFloat("c");
	}


This short code fragment instantiates a DriverManager object to connect to a database driver and log into the database, instantiates a Statement object that carries your SQL language query to the database; instantiates a ResultSet object that retrieves the results of your query, and executes a simple while loop, which retrieves and displays those results. It's that simple.
(他的tutorial居然先给人看一段代码,然后说It's that simple。不知道对于刚开始接触jdbc的人来说,这段代码是不是如他所说的that simple了)

2.JDBC Product Components

JDBC includes four components:
(4个组成部分)
The JDBC API — 
(JDBC API分在2个包内java.sql和javax.sql。都包含在SE和EE的版本内。主要用于编程。)
The JDBC™ API provides programmatic access to relational data from the Java™ programming language. Using the JDBC API, applications can execute SQL statements, retrieve results, and propagate changes back to an underlying data source. The JDBC API can also interact with multiple data sources in a distributed, heterogeneous environment.

The JDBC API is part of the Java platform, which includes the Java™ Standard Edition (Java™ SE ) and the Java™ Enterprise Edition (Java™ EE). The JDBC 4.0 API is divided into two packages: java.sql and javax.sql. Both packages are included in the Java SE and Java EE platforms.

JDBC Driver Manager — 

(驱动管理和扩展包里的DataSource.DriverManager是核心)
The JDBC DriverManager class defines objects which can connect Java applications to a JDBC driver. DriverManager has traditionally been the backbone of the JDBC architecture. It is quite small and simple.

The Standard Extension packages javax.naming and javax.sql let you use a DataSource object registered with a Java Naming and Directory Interface™ (JNDI) naming service to establish a connection with a data source. You can use either connecting mechanism, but using a DataSource object is recommended whenever possible.

JDBC Test Suite  — 

(测试包)
The JDBC driver test suite helps you to determine that JDBC drivers will run your program. These tests are not comprehensive or exhaustive, but they do exercise many of the important features in the JDBC API.

JDBC-ODBC Bridge — 
(桥)

The Java Software bridge provides JDBC access via ODBC drivers. Note that you need to load ODBC binary code onto each client machine that uses this driver. As a result, the ODBC driver is most appropriate on a corporate network where client installations are not a major problem, or for application server code written in Java in a three-tier architecture.



This Trail uses the first two of these these four JDBC components to connect to a database and then build a java program that uses SQL commands to communicate with a test Relational Database. The last two components are used in specialized environments to test web applications, or to communicate with ODBC-aware DBMSs.


3.JDBC Architecture
(JDBC还分什么两层架构,三层架构??跟他没关系咯)
The JDBC API supports both two-tier and three-tier processing models for database access.

In the two-tier model, a Java applet or application talks directly to the data source. This requires a JDBC driver that can communicate with the particular data source being accessed. A user's commands are delivered to the database or other data source, and the results of those statements are sent back to the user. The data source may be located on another machine to which the user is connected via a network. This is referred to as a client/server configuration, with the user's machine as the client, and the machine housing the data source as the server. The network can be an intranet, which, for example, connects employees within a corporation, or it can be the Internet.

In the three-tier model, commands are sent to a "middle tier" of services, which then sends the commands to the data source. The data source processes the commands and sends the results back to the middle tier, which then sends them to the user. MIS directors find the three-tier model very attractive because the middle tier makes it possible to maintain control over access and the kinds of updates that can be made to corporate data. Another advantage is that it simplifies the deployment of applications. Finally, in many cases, the three-tier architecture can provide performance advantages.



Until recently, the middle tier has often been written in languages such as C or C++, which offer fast performance. However, with the introduction of optimizing compilers that translate Java bytecode into efficient machine-specific code and technologies such as Enterprise JavaBeans™, the Java platform is fast becoming the standard platform for middle-tier development. This is a big plus, making it possible to take advantage of Java's robustness, multithreading, and security features.
(这段话有点像广告。是不是说EJB之前,java还不能跨入三层架构的行列?)
With enterprises increasingly using the Java programming language for writing server code, the JDBC API is being used more and more in the middle tier of a three-tier architecture. Some of the features that make JDBC a server technology are its support for connection pooling, distributed transactions, and disconnected rowsets. The JDBC API is also what allows access to a data source from a Java middle tier.
(支持连接池,分布式的事务和非连接的结果集。使JDBC看起来更像服务段技术。)

分享到:
评论
1 楼 shenyu 2008-05-10  
努力学习中。希望LZ加油

相关推荐

    jdbc api tutorial and reference

    JDBC(Java Database Connectivity)是Java平台上的一个标准接口,由Sun Microsystems开发并纳入Java Development Kit (JDK) 中,它为Java程序员提供了一种统一的方法来访问各种数据库。《JDBC API教程与参考》是由...

    JDBC API Tutorial and Reference 3rd Edition

    《JDBC API Tutorial and Reference 3rd Edition》是数据库编程领域一本重要的参考资料,它深入浅出地介绍了Java数据库连接(JDBC)API的使用方法。这本书由Addison Wesley出版,旨在帮助开发者理解和掌握如何在Java...

    JDBC API Tutorial and Reference 3rd Edition (2003).chm

    JDBC™ API Tutorial and Reference, Third Edition By Maydene Fisher, Jon Ellis, Jonathan Bruce Publisher : Addison Wesley Pub Date : June 13, 2003 ISBN : 0-321-17384-8

    Sun Java Tutorial(错误/参见另一个文件)

    实在对不起大家,之前传的这个有问题。是我的疏忽,不是我有意骗大家分。我重新上传了。这个就不要再下了。 #非常棒的一本入门教程,配合java api doc 中文看,黄金搭档。

    JDBC API教程与参考手册(第三版)前言+目录+第一,二章

    通过以上章节的介绍,我们可以看出,《JDBC API教程与参考手册》第三版是一本系统、全面地介绍了JDBC技术的书籍。从基本概念到核心API,再到高级特性与最佳实践,本书都做了详尽的讲解。对于希望深入了解和掌握JDBC...

    SUN Java certificate tutorial.rar

    在这个"SUN Java certificate tutorial.rar"压缩包中,很显然包含了一个关于如何理解和使用Java证书的教学资源。 首先,Java证书是公钥基础设施(PKI)的一部分,它由可信的证书颁发机构(CA)签署,以确认一个实体...

    JDBC.pdf

    - JDBC教程:[http://java.sun.com/docs/books/tutorial/jdbc/](http://java.sun.com/docs/books/tutorial/jdbc/) - 可用JDBC驱动列表:[http://industry.java.sun.com/products/jdbc/drivers/]...

    J2EE Tutorial中文版

    <br>《The J2EETM Tutorial 中文版》的作者是Sun Microsystem公司Java开发小组资深的开发人员,与另一部取得空前成功的《The JavaTM Tutorial》一样,建立了与读者之间最为有效的交互途径。同时,在本书的...

    FMC-IMAGEON - Building a Video Design from Scratch Tutorial

    在这个"FMC-IMAGEON - Building a Video Design from Scratch Tutorial"中,我们将会深入探讨如何从零开始构建一个视频设计项目。教程的标题暗示了这是一次全面的学习过程,旨在帮助用户掌握视频设计的基础知识和...

    A Complete Tutorial on Tree Based Modeling from Scratch (in R——& Python)

    通过一个实例代码完全描述了决策树的构造过程。具有很好的学习和借鉴意义。(PDF文档)

    .-.jdbc.api.tutorial.and.reference

    JDBC API知道和开发引用

    The J2EE Tutorial-中文版.pdf

    - JDBC教程:[http://java.sun.com/docs/books/tutorial/jdbc](http://java.sun.com/docs/books/tutorial/jdbc) - 多线程教程:[http://java.sun.com/docs/books/tutorial/essential/threads]...

    Sun权威教程--《J2EE Tutorial中文版》

    《The J2EETM Tutorial 中文版》的作者是Sun Microsystem公司Java开发小组资深的开发人员,与另一部取得空前成功的《The JavaTM Tutorial》一样,建立了与读者之间最为有效的交互途径。同时,在本书的编写过程中,也...

    Sun Directory Server Install Tutorial

    Sun Directory Server 是一款基于 Lightweight Directory Access Protocol (LDAP) 的目录服务软件,由 Sun Microsystems 开发。在进行 Sun Directory Server 的安装教程中,有几个关键的知识点是必须了解的,这些...

    Tutorial Master 22.0.7.2

    Tutorial Master是一个编辑器扩展,允许您创建您的游戏互动教程惊人的快速和容易! Tutorial Master2 已经建立了从地面到成为最好的教程制作解决方案之一!教导新玩家(以及潜在用户)如何以你所希望的方式玩游戏! 用户...

    j3d_tutorial\ j3d教程sun官方版

    "j3d_tutorial\ j3d教程sun官方版" 提供的是Sun官方的Java 3D教程,这是一份非常宝贵的资源,对于学习和理解Java 3D编程至关重要。 Java 3D API允许开发者通过对象模型来构建3D世界,这些对象包括几何形状、变换、...

    JDBC API教程与参考手册(第三版)其余部分 PART 3

    JDBC API教程与参考手册(第三版)其余部分 PART 3

Global site tag (gtag.js) - Google Analytics