Chapter 18. Database Access with SQL

This chapter shows how you can communicate with a database server using the JDBC API of the java.sql package. JDBC is an API that allows a Java program to communicate with a database server using Structured Query Language (SQL) commands. Note that JDBC is a SQL API, not an embedded SQL mechanism for Java.

The java.sql package provides a fairly straightforward mechanism for sending SQL queries to a database and for receiving query results. Thus, assuming that you already have experience working with databases and SQL, this chapter should be relatively easy to understand. On the other hand, if you have not worked with databases before, you’ll need to learn basic SQL syntax and some general database programming concepts before you can really take advantage of the examples in this chapter and JDBC in general. I’ll try to explain some of the basic concepts as I go along, so that you can get a sense of what is possible with JDBC, but full coverage of database programming is beyond the scope of this chapter. Java Enterprise in a Nutshell contains a more thorough introduction to JDBC, a SQL reference, and an API quick-reference for the java.sql package.

In order to run the examples in this chapter, you need access to a database, and you have to obtain and install a JDBC driver for it. If you don’t already have a database server to work with, you can use one of the excellent open source databases available today. The examples in this chapter ...

Get Java Examples in a Nutshell, 3rd 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.