Java Reference
In-Depth Information
19.4
Java and Database Connections
It is a capital mistake to theorize before one has data.
SIR ARTHUR CONAN DOYLE ( Sherlock Holmes ) , Scandal in Bohemia
As an example of how Java has been extended to interact with other software systems,
in this section, we will briefly describe how Java interacts with database management
systems. This is not a complete enough introduction to allow you to immediately start
writing Java code for database manipulations. The intent of this section is to let you
know what kinds of things are available to you for database programming in Java.
SQL
SQL is a standard for database access that has been adopted by virtually all database
vendors. The initials SQL stand for Structured Query Language. SQL is pronounced
either by saying the letters or by saying the word “sequel.” SQL is a language for for-
mulating queries for a relational database. SQL is not part of Java, but Java does have a
library (and accompanying implementation software) known as JDBC that allows you
to embed SQL commands in your Java code.
SQL works with relational databases. Most commercially available database manage-
ment systems are relational databases. A relational database can be thought of as a collec-
tion of named tables with rows and columns, such as those shown in Display 19.7. In this
brief introduction we will not go into the details of the constraints on tables, but to see that
there are some constraints, note that in the three tables in Display 19.7, no relationship is
repeated. For example, if we had one entry for each book with all the information—title,
author, ISBN number 1 , and author's URL—then there would be two entries giving Dan
Simmons' URL, since he has two topics in our database.
The following is a sample SQL command:
SQL
SELECT Titles.Title, Titles.ISBN, BooksAuthors.Author_ID
FROM Titles, BooksAuthors
WHERE Titles.ISBN = BooksAuthors.ISBN
This will produce the table shown in Display 19.8. That table contains all titles with
matching ISBN number and author ID, given in Display 19.8. The ISBN number is
the bridge that connects the tables Titles and BooksAuthors .
1 The ISBN number is a unique identification number assigned to (almost) every book published.)
Search WWH ::




Custom Search