Chapter 6. Persisting Your Application Using Databases

In the previous chapter, you learned about how to persist the state of your application using file-based mechanisms. This is a useful way to handle things in a single-user model, but when multiple users need to share the same data, databases are the solution. In this chapter, you learn about how to persist your application to a database.

Java is an object-oriented programming language. Database programming and object-oriented design can feel like oil and water. Because of this difference between the two technologies, there are two schools of thought for database development in an object-oriented environment. The first is that the database is just a resource, like any other, and the API that communicates with the database needs to have robust tools related to working tabular data. The second school of thought is that the objects in the application represent the data, there is no separation; therefore, the access should be seamless.

This chapter is organized around those two thoughts. The first section explores the JDBC 4.0 API, which provides robust tools for dealing with tabular relational data. In my view, JDBC is one of the most highly used and significant APIs developed for the Java platform. It's one of the reasons Java is portable across platform and database alike.

The second section of the chapter explores the Object Relational Mapping (ORM) approach. An ORM framework is used to abstract data access. This allows your application ...

Get Professional Java® JDK®, 6th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.