JDBC   «Prev  Next»
Lesson 4Relational Databases
Objective Explain the relational model.

JDBC, Databases and the Relational Model

Question: What is the relational model for relational databases and what is its relation to the JDBC API?
The relational model is a way of organizing data in a relational database by storing it in tables with rows and columns. In this model, each table represents a different entity or relationship between entities, and each row represents a unique instance of that entity or relationship. The JDBC API (Java Database Connectivity API) is a Java API for connecting to relational databases and performing database operations, including creating and modifying tables, inserting and retrieving data, and executing queries.
The JDBC API is designed to work with the relational model of databases, as it provides a standard way to interact with SQL databases through the use of SQL statements. SQL is a language for querying and manipulating data in relational databases, and the JDBC API provides a way for Java applications to send SQL statements to a database server and retrieve the results. Using the JDBC API, Java applications can interact with relational databases by sending SQL statements to the database server and receiving the results. This allows applications to read and write data to and from the database, as well as perform more complex operations such as joining tables, grouping data, and executing stored procedures.
Overall, the JDBC API is closely related to the relational model for databases, as it provides a way for Java applications to interact with SQL databases in a standard way that is compatible with the relational model. This allows Java applications to work with a variety of SQL databases using a consistent set of APIs and techniques.


JDBC and Relational Databases

Because understanding relational databases is crucial to understanding JBDC, this lesson will discuss them in more detail.
In the previous lesson, you were introduced to several terms associated with relational databases: tables, rows, and columns. The example below illustrates how they apply to the pieces of a database and what the table might look like.

Customer Number Name Address Phone Number Route Publication Account Current?
100 Smith, Joe 123 Main St 555-1000 1 The Times Yes
101 Doe, Jane 789 Dusty Rd 555-1234 2 Nightly News No

As illustrated above, the intersection of a row with a column represents a particular piece of information about a individual record. So, if your database is a collection of customer information, each customer might be represented by a row. The pieces of information you must keep about that customer (name, address, etc.) are in the separate fields or elements of that customer record represented by that row. The entire collection of customer records is held in a table. As you add more customers you will add more rows. As the business grows, you will likely add more tables to help manage the extra information you need to track. Perhaps the number of customers increased to the point where one carrier can't deliver all our papers. You then hire more delivery people and keep track of them in another table such as the one described below.

Route Name Address Phone Number
1 Melville, Herman 1 Long St 555-9999
2 Joyce, James 10 Dublin Ln 555-0000


Information representation

This table format is a straightforward way to represent the information you want to preserve. It's convenient and it's often easy to cast your data into this form. There is another major advantage that comes with relational database systems. There is a standardized language for managing the data they hold. It isn't sufficient simply to have a handy way to store your information. You want to use it to help you run your business.
For example, you certainly will want a way to add and delete rows (records) from your table. You will also want some way to retrieve information from your individual tables. Further, if you keep information in several tables, you will likely want to perform queries that pull information together from several tables. Using the tables above, you may want to get a list of all the customers grouped by carrier name. To do that you would have to relate data from the first table to the second. SQL provides the mechanism to perform these operations.
More on the relational model can be found at Relational Model.

SQL history

SQL was originally developed by Dr. E.F. Codd at IBM in the early 1970s.
It provides a rigorously defined method for managing sets of data and our database tables correspond to these data sets.
As you might suspect, there are variations and extensions to these basic operations. We will take the opportunity to explore them as we go along.
In the next lesson, SQL will be discussed.


JDBC architecture - Exercise


Click the Exercise link below to challenge your skills at describing your JDBC architecture.
JDBC Architecture - Exercise