29.3.6 Querying the Authors Table

Figure 29.1 performs a simple books database query that retrieves the Authors table and displays its data. The program illustrates using JPA to connect to the database and query it. You’ll use a dynamic query created in main to get the data from the database—in the next example, you’ll use auto-generated queries in the persistence unit to perform the same query and others. In Section 29.5, you’ll learn how to modify a database through a JPA persistence unit. Reminder: Before you run this example, ensure that the Java DB database server is running; otherwise, you’ll get runtime exceptions indicating that the app cannot connect to the database server. For details on starting the Java DB server, see Section 29.3.1 ...

Get Java™ How To Program (Early Objects), Tenth Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.