Objects from a Database: an overview

Most Java applications work with data from a database, so many of their classes model a table, with one object for each row.

Journeyman · Java · OOP · Updated

By

Most Java applications are data-driven. This means that the information they display to the user comes from a database, or information that they get from a user will be saved to a database. In either case, the application needs to interact with a database. Because we use databases so frequently, many of the objects we need to define in Java are objects that come from a database.

Think of the tables in the Northwind database. The categories table has at least 8 rows. Each row represents 1 category. In Java, we would create a category object, then we would convert each database row into a Java object.

Notice that the categories table diagram closely resembles the UML Category class diagram.

The categories table beside the UML Category class: each column (category_id, category_name, description) becomes a private variable (categoryId, categoryName, description) with a getter and a setter

Cheat sheets