Connecting to the Database

Now I am going to dive into the details about JDBC calls and how to use them. The examples in this book should run on your system regardless of the database or driver you use. The one phase when it is hard to achieve portability is the first step of connecting, because you have to specify a driver. I’ll discuss that first to get it out of the way.

Figure 3.4 shows how an application uses JDBC to talk to one or more databases without knowing the details concerning the driver implementation for that database. An application uses JDBC as an interface through which it passes all its database requests.

JDBC shields an application from the specifics of individual database implementations

Figure 3-4. JDBC shields an application from the specifics of individual database implementations

When you write a Java database applet or application, the only driver-specific information JDBC requires from you is the database URL. You can even have your application derive the URL at runtime—based on user input or applet parameters.

Get Database Programming with JDBC & Java, Second 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.