Before you write a JDBC™ application, you need to set up a database called
COFFEEBREAK
. You learn how to create a database through your vendor documentation. Once you have set up theCOFFEEBREAK
database, continue with this lesson.We strongly suggest that you use the Java DB database bundled with Netbeans, to work through this tutorial. Directions for setting up and connecting to the Java DB™ and using the NetBeans™ IDE can be found here.
Overview
Assume that our sample database is being used by the proprietor of a small coffee house called The Coffee Break, where coffee beans are sold by the pound and brewed coffee is sold by the cup. To keep things simple, also suppose that the proprietor needs only two tables, one for types of coffee and one for coffee suppliers.To store data in the database, you create tables. Later, when you learn about creating the tables used as examples in this tutorial, the tables will be in the default database. We purposely kept the size and number of tables small to keep things manageable.
Once you have created the database and tables to store the data, you'll a open a connection with your DBMS. You also need to know some SQL code. After that, you'll discover how easy it is to use JDBC to pass SQL statements to your DBMS and then process the results that are returned.
Note: The code in this lesson has been tested on most of the major DBMS products. However, you may encounter some compatibility problems using it with older ODBC drivers with the JDBC-ODBC Bridge.