`
桔红糕
  • 浏览: 41325 次
  • 性别: 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加油

相关推荐

Global site tag (gtag.js) - Google Analytics