Chapter 11. JDBC

These common thoughts are expressed in a shared public language, consisting of shared signs... a sign has a “sense” that fixes the reference and is “grasped by everybody” who knows the language...

Noam Chomsky, Language and Thought

JDBC is one of the oldest programming APIs in the Java platform. In fact, it is the first of the enterprise APIs that eventually became the J2EE platform. Its goal is to create a shared public language for Java access to any database engine.

SQL lies at the heart of the JDBC API. I therefore assume a basic knowledge of SQL in this chapter. Chapter 10 contains a SQL tutorial if you need some background.

Architecture

Working with leaders in the database field, Sun developed JDBC as a unified API for database access. As part of the JDBC design process, they kept in mind three main goals:

  • JDBC should be an SQL-level API.

  • JDBC should capitalize on the experience of existing database APIs.

  • JDBC should be relatively simple.

As an SQL-level API, JDBC enables you to construct SQL statements and embed them inside API calls. You are essentially using JDBC to make a smooth transition between the SQL and Java. Your application sends a query to the database as SQL and gets the results back through a Java object. Any database error you encounter is thrown to your application as a Java exception.

Database programming in most languages today is very different from what it was just seven years ago. It used to be that each database engine had its own proprietary ...

Get Java Database Best Practices 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.