IN THIS CHAPTER
Configuring JDBC drivers
Creating a connection
Executing SQL statements
Retrieving result data
Updating and deleting data
JDBC — Java Database Connectivity — is a Java feature that lets you connect to almost any relational database system, execute SQL commands, and process the results, all from within a Java program. In this chapter, you set up JDBC and use it to access data in a MySQL database.
If you aren’t familiar with the basics of SQL, read the previous chapter before tackling this chapter.
Before you can write a Java program to access a database via JDBC, you must first install a driver that links Java’s database API classes to an actual database. Correctly setting up the driver can be tricky, but once you get it working, accessing the database is easy.
To install the JDBC driver for MySQL, browse to
www.mysql.com/products/connector and click the link for JDBC Driver for MySQL (Connector/J)