O'Reilly logo

Java All-in-One For Dummies, 4th Edition by Doug Lowe

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 4

Using JDBC to Connect to a Database

In This Chapter

arrow Configuring JDBC drivers

arrow Creating a connection

arrow Executing SQL statements

arrow Retrieving result data

arrow 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.

Setting Up a Driver

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)

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required