O'Reilly logo

Big Java, 4th Edition by Cay Horstmann

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 22. Relational Databases

CHAPTER GOALS

  • To understand how relational databases store information

  • To learn how to query a database with the Structured Query Language (SQL)

  • To connect to a database with Java Database Connectivity (JDBC)

  • To write database programs that insert, update, and query data in a relational database

In Chapter 19 you saw how to store data in a file. When you store data, you will want to be able to add more data items, remove data, change data items, and find items that match certain criteria. However, if you have a lot of data, it can be difficult to carry out these operations quickly and efficiently. Because data storage is such a common task, special database management systems (DBMS) have been invented that let the programmer think in terms of the data rather than file storage. In this chapter you will learn how to use SQL, the Structured Query Language, to query and update information in a relational database, and how to access database information from Java programs.

Organizing Database Information

Database Tables

A relational database stores information in tables. Figure 1 shows a typical table. As you can see, each row in this table corresponds to a product. The column headerscorrespond to attributes of the product: the product code, description, and unit price. Note that all items in a particular column have the same type: product codes and descriptions are strings, unit prices are floating-point numbers. The allowable column types differ somewhat from ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required