JDBC   «Prev  Next»
Lesson 7JDBC architectural models
ObjectiveExplain JDBC as it functions in two and n-tier System Design

JDBC Architectural Models

A two-tier database model is a graphical way of representing the relationship between an application and a database.
A traditional two-tier database model applies to a scenario where an application communicates directly with a database. The application is one tier, and the DBMS is the second. The main function of JDBC in a two-tier database model is to connect the application directly to the database.

Client/Server Configuration

When designing JDBC Architecture, what needs to be taken into consideration when designing for 1) client-server and 2) multi-tier architectures?
When designing the JDBC architecture for client-server and multi-tier architectures, there are several considerations that need to be taken into account:
  1. Client-server architecture:
    1. The JDBC driver should be installed on the client-side to communicate with the database server.
    2. The network latency between the client and the server should be considered to optimize performance.
    3. Security measures such as encryption should be implemented to secure the data transmission over the network.
    4. Connection pooling should be used to avoid creating too many connections to the database server.
  2. Multi-tier architecture:
    1. The JDBC driver should be installed on the application server, which is responsible for handling the communication with the database server.
    2. The application server should be designed to handle multiple concurrent requests from clients.
    3. Load balancing and failover mechanisms should be implemented to ensure high availability and scalability.
    4. Security measures such as authentication and authorization should be implemented to protect the data.
    5. Connection pooling should be used to manage database connections efficiently and avoid creating too many connections.

Overall, the JDBC architecture should be designed with performance, scalability, security, and reliability in mind, depending on the specific requirements of the client-server or multi-tier architecture.

This two-tier model is commonly called a client/server configuration.
The JDBC driver delivers the user commands to the data source, and returns the results from the datasource to the user, as you see in the graphic below.

two-tier design database model static graphic
Two-tier design database model static graphic

The n-tier model

In the Java-related two-tier model, the piece added to the client is a JDBC driver.
This provides the request/response communication between the two tiers.


Two-tier model

The benefit of the two-tier model is its simplicity. In situations where more flexibility is required developers turn to an n-tier model.
In its simplest form, an n-tier design has three tiers. Those three elements are:
  1. Client
  2. Server
  3. Database.

The server is positioned in the middle of the model. Client applications communicate with the server via some type of middleware such as Java RMI or CORBA. The server communicates with the database using a database protocol such as JDBC the same way the client communicated with the database in the two-tier model. This approach is flexible enough to allow for multiple servers and databases, hence the "n" reference as a way to represent an arbitrary number of those entities. The following MouseOver illustrates the functions of an n-tier model.

JDBC Metadata
Clienter Server Architecture consisting of 3 layers
Clienter Server Architecture consisting of 3 layers

  1. Client: This is the first tier in the three tier model and requests are sent to the second tier where commands are issued to the third tier for data and the data is returned.
  2. Server: The application server with the JDBC server technology controls data source access from the middle tier. The server processes data server requests and results and since the data to the clients Java applet or HTML browser
  3. The data source processes commands from JDBC sending the results back to the second tier application server


JDBC Architectural Models and the n-tier Model

n-tier-model
1) Client GUI: This is the first tier in the three-tier-model. Requests are sent to the second tier where commands are sent to the second tier where commands are issued to the third tier for data
2) Application Server: The application server, with JDBC server technology, controls data source access from the middle tier, processes data server requests/results, and sends the data to the client HTML browser
3) Database: The data source processes commands from JDBC, sending the results back to the second tier application server.

As we will observe by examining questions and answers, JDBC provides a powerful, comprehensive interface for accessing databases from Java programs and servlets. The JDBC API allows any Java program, even an applet and servlet, to connect to a relational database management system (RDBMS) and perform queries and transactions. Servlets and JDBC are ideal for creating dynamic contents. Using JDBC from a Java servlet involves a three-tier distributed application, consisting of a user interface (the web browser), business logic (a series of Java servlets), and database access. The user interface is an HTML file in a browser. The middle tier is a Java servlet that handles requests from the client web browser and provides access to the third tier, a database accessed via JDBC.

The main function of JDBC in an n-tier database model is to allow the developer to split request/response processing into two portions of code. Part of the code processes on the client side, which is mostly data presentations. The other part processes on the server side, which consists of mostly business rules and database access modules.

Elements of n-tier architecture

The elements of the n-tier architecture include presentation services (or the presentation layer), process services (or the middle layer), and business services (or the business layer). These services perform different functions, as explained in the following table.

Service Function
Presentation services presentation services The presentation services provide the user interface to the system. This can be achieved through traditional graphical interfaces (such as a Windows PC) and terminals, or through other technologies such as Web browsers, interactive TV, kiosks, ATMs, and interactive voice response (IVR).
Process services process services The process services act as a buffer between the presentation and the data. In an n-tier architecture, alluser access to the data occurs through presentation services, which communicate with the process services. Typical process services, then, include customer searches, product updates, archiving of data, and complex business rule checks. This tier would also include services that were not necessarily tied to the presentation layer, such as scheduled batch processes or automatic event handling.
Business services Business services The data services provide the data on which the process services work. The database server typicallyfills this role, but it may also consist of file systems, sensors, telemetry, etc.


The function of middleware

The middleware ties all the tiers together. Any client/server architecture, whether two-tiered or n-tiered, requires middleware to provide the communications link among the layers. Middleware is normally provided as generic toolsets that can be configured to support your particular set of services.
Examples of these are
  1. CorbaCORBA,
  2. RMI, and
  3. in the Microsoft world, DCOM and .NET.

Physically, these three tiers can be implemented in a wide variety of ways, which is where multi-tier comes in.
As illustrated in the following graphic, any of the services can be set up as multiple layers, with one service calling other services to perform specialist tasks.
The following table describes the characteristics of an n-tier approach.

Characteristic Description
Characteristic One All business logic resides in the middle-tier server application. This includes all database schema, connection, SQL statement creation, and SQL error handling. The server may also perform data conversion services to the client. For instance, the client may need database information in the form of a tree, a Java object, a list of Java objects, or a hashmap of Java objects. By placing this logic in the server it is written once and reused by many (potentially different) client applications
Characteristic Two An n-tier architecture facilitates the thinnest possible client application (often a UI). Clients, freed from knowing about the database organization, table names, column names, and SQL syntax, become solely a presentation and input layer. The database may be modified without requiring modification and redeployment of the clients.
Characteristic Three Solutions with an n-tier architecture have separate software entities with well-defined interfaces that allow parallel development of individual tiers by application specialists.
Characteristic Four An n-tier architecture allows client notification of database changes. Since the middle tier knows when database changes occur and which entities were modified, it can call back the client so the client can intelligently decide when to refresh its displayed data. Less desirable alternatives are for the UI to either blindly refresh its data periodically or refresh its data only when the user requests it. These options waste network bandwidth and have a higher probability of showing stale data.
Business benefits are provided by an n-tier architecture, even when compared to a two-tier client/server. In the next lesson, you will begin to apply guidelines for defining the use of JDBC in a business solution.

JDBC Architecture - Quiz

Click the Quiz link below to test your knowledge of JDBC architecture and models.
JDBC Architecture - Quiz