Implementation of Distributed Database interoperability in a Java-based Web Environment

Source: Internet
Author: User
Tags driver manager sybase database

Author:Li Yuming Mo Qian Xu Ming
1. Working Principle of JDBC
JDBC (Java database connectivity) is a trademark registered by Sun, representing the Java programming interface API used to execute SQL statements, it includes a series of classes and interfaces written in Java, providing standard application programming interfaces for database developers to develop database applications.
1.1 JDBC Overview
Using JDBC can easily use SQL statements to access any commercial database. That is to say, through the JDBC API, database application developers do not need to write one program to access the Sybase Database, write another program to access the Oracle database, and write another 3rd program to access the Informix database. Instead, write one program using the jdbc api to send the SQL query statement to the appropriate database. At the same time, the Java language is used to write applications, which is platform-independent and does not need to write different applications for different platforms. Therefore, developers who use Java and JDBC to write database applications can "write once and use it everywhere ".
JDBC extends the functions of the Java language. For example, using Java and JDBC, you can create a web page with a Java application applet that can obtain information from a remote database, you can also develop an application that enables employees to access one or more internal databases through the Intranet.
Using Java and JDBC will make it easy and economical to collect and send information. companies and enterprises can continue to retain their previous database systems, and even these database systems are different from each other, you can still easily access the above information. In addition, the time required to develop a new database application will be greatly shortened.
1.2 JDBC Architecture
The architecture of JDBC contains four components.
1. JDBC application. JDBC applications are responsible for interaction between users and user interfaces, and call JDBC object methods to provide SQL statements and extract results.
2. JDBC driver manager. The JDBC driver manager loads and calls drivers for applications.
3. JDBC driver. The JDBC driver calls the JDBC object method, sends an SQL request to the specified data source, and returns the result to the application. The driver is also responsible for interacting with any necessary software layer that accesses the data source.
4. data source. A data source consists of a dataset and an environment associated with it. It mainly refers to the database systems of various database vendors.
Like ODBC, the programming interfaces provided by JDBC to programmers are composed of two parts: the application-oriented programming interface jdbc api and the driver interface JDBC driver API for the underlying development. JDBC APIs are provided for application programmers, while JDBC driver APIs are provided for various commercial database vendors. The JDBC drivers of various commercial database manufacturers are automatically and centrally managed by the JDBC driver manager.

2. How RMI works
In a distributed system, the communication between programs on different hosts can be directly programmed through socket, which is the underlying method, you can also use the Remote Procedure Call mechanism with a higher level. However, for Java, a pure object-oriented network programming language, these methods and mechanisms inevitably undermine Java's object-oriented features. What Java RMI technology needs to do is to reference objects on different virtual machines in a distributed object environment.
2.1 RMI Overview
RMI is a new technology in the Java System. Java is a pure object-oriented language. Every program entity is submitted as an object. In order to keep Java programming in a distributed environment this feature, sum company puts forward the concept of distributed objects, which are distributed objects (remote objects) mutual reference provides an abstract object-level mechanism suitable for object semantics. This is RMI. It makes Java programming in a distributed environment or network communication between Java programs no longer involve underlying protocols and data encoding and decoding, making it simpler and more natural.
2.2 RMI Architecture
As shown in figure 1, the RMI system consists of the following three layers: stub/skeleton layer, remote reference layer, and transmission layer. The boundaries of each layer are defined by specific interfaces and protocols. Therefore, each layer is independent of its adjacent layers, that is, the Implementation changes of a layer, it does not affect other layers.


Figure 1 RMI Architecture

The stub/skeleton layer is the interface between the Java program and other parts of the RMI system. In the RMI system, this layer actually plays the role of proxy. stub and skeleton are the agents of the customer program and service program respectively. On the client side, the client program sends a remote method call request to stub, and stub is responsible for passing these requests to the server and returning the call results to the client program. On the server side, the call request from the client is received by skeleton, and skeleton is responsible for calling the corresponding object method for the service. The call result is also returned to the client by skeleton.
The remote reference layer refers to the semantic Implementation of Remote Object Reference. All operations on remote objects, including copying objects, are managed by the remote reference layer.
The transport layer is responsible for listening to incoming call requests, establishing connections for them, and managing and monitoring these connections, at the same time, a remote object table is maintained for all remote objects in the address space to locate the target of Remote Call.
2.3 Object serialization Technology
Object serialization is also used in the RMI system ). Object serialization is essentially the code for Java objects. During a remote method call, it is responsible for first encoding the Java objects to be transmitted by the sender into word throttling before network transmission, on the receiver side, it is responsible for restoring the received byte stream to a Java object, thus achieving transparent transmission of objects in different address spaces.
2.4 RMI Objectives
RMI is designed for the Java language. Its goal is to implement seamless remote calls to objects on different virtual machines, and naturally integrate the distributed object model into the Java language, it is possible to retain Java's object-oriented features in terms of semantics, as well as the security provided by the Java Runtime Environment.
In the RMI system, the Implementation Details of all remote method calls are transparent to Java programs. The reference between remote objects is as simple and natural as referencing local Java objects, conforms to the object-oriented semantics.
In RMI, calling remote methods is very important. syntactically, it is consistent with calling local methods.

3 Implementation of Distributed Database interoperability in a Java-based Web Environment
3.1 Implementation of JDBC's Interoperability with heterogeneous databases
To access various heterogeneous databases in JDBC, there is a simple and quick way to Use ODBC, which is a mature database application technology, it provides unified access interfaces for various heterogeneous databases. Therefore, we only need to use the JDBC-ODBC bridge driver to achieve transparent access to a variety of relational databases, so that JDBC applications and their drivers are independent of the database.
3.2 use RMI to solve Java's limitations on applet Security
For JDBC applications, the biggest advantage of RMI is that it can surpass the network security restrictions imposed by Java applet. As the client of the RMI system, the applet is downloaded from the host node where the RMI server is located and can access resources on the RMI server, it can send database access requests to the server and receive data returned by the server. As a Java application RMI server program, it does not have the same restrictions as applet. It can access resources on other hosts, including databases. It is responsible for receiving database access requests from the client applet, accessing database resources through JDBC based on requests, and returning the access result data to the client applet. In fact, the RMI server program becomes a proxy for the client applet to access the database, blocking Java's security restrictions on the applet.
3.3 Use RMI and JDBC to implement a three-layer Client/Server structure model
An Improvement Method for the traditional layer-2 structure is to adopt the client/server layer-3 structure, and add an "intermediate layer" between the client and the database server ", all database access on the client is performed by the middle layer. The access result data is received by the middle layer from the database server and forwarded to the client. The middle layer actually acts as a proxy.
The RMI server serves as the intermediate layer between the customer and the database server and is responsible for data communication between them. The database access request of the customer's apple T is submitted to the database through the RMI server, and the access result is also transmitted by the database server to the customer applet through the RMI server. The RMI server is actually a JDBC application. It communicates with the client applet through the RMI system and serves it. It establishes a connection with the database server through JDBC, the connection between the client Applet and the database server is realized.
The combination of RMI and JDBC enables remote data access in the Web environment. One obvious advantage is that, as a client's Java program, it no longer needs to call the lower-layer jdbc api, instead, the server provides corresponding high-level APIs. As an RMI server, you can add certain constraints to the client's applet requests, increasing the flexibility and security of the system.
3.4 implement one n-layer Client/Server structure
The layer-3 model described above is the basis for developing distributed database applications in the Web environment. Based on the features that RMI supports point-to-point communication (that is, RMI programs on one node can be both server programs and client programs, you can implement an application in layer-N Client/Server mode as shown in step 2.


Figure 2 Application of layer-N Client/Server mode in distributed databases

This application system is composed of many servers distributed on different host nodes and their direct clients. Each server and its direct client constitute a three-tier structure system. The server is composed of HTTP server, RMI system (server/Cl ient), JDBC, ODBC, and SQL database server, each Server communicates with other server and direct clients connected to it through the RMI system. In the entire system, it serves as a server, providing data services for direct customers and other servers, and as a client, and can apply for data services from other servers.
In actual applications, each server has a table that records the addresses of other servers connected to it. Each server's direct client can send a database access request to its server, the server first queries the database on its own node. If the corresponding information exists, the server returns it to the client. Otherwise, the server sends a query request to other servers according to the address table; if the other servers have the relevant information, they are also returned to the client. Otherwise, the client fails to query. Obviously, all clients can transparently access the databases on all servers. In this way, you can implement a distributed database application in a Web environment.

4. Summary
Using JDBC and RMI to implement distributed database interoperability in the web environment is an attempt to apply Java technology and an improvement to the traditional C/S architecture, it has the advantages of simplicity and efficiency. Combined with the various good features of Java, especially the emerging RMI technology and the JDBC technology supported by the industry, I believe it will develop towards standardization, and will be more widely used.

Author unit:Key Laboratory of parallel and distributed processing, Changsha National University of Defense Technology (410073)

References
 
1 Rasmussen B .WDB-A Web interface to SQL databases. European Southern Observatory, http://arch-http.hq.eso.org/bfrasmus/wdb/wdb.html,1997
2 naguyen T, srin1_v. accessing relational database from the World Wide Web. ACM sigmod '96 Montreal, Canada, 1996
3 yaylor A. JDBC developer's resource. Prentice Hall PTR, http://www.preh all.com, 1997

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.