No Java programmer is complete without knowledge of Java database connectivity, or JDBC for short. In this 2 part article Nitin teaches us JDBC from the inside out.
Database Programming With Java + JDBC: Part 1/2 - Before We Start Coding (Page 3 of 6 )
In order to do some hands on coding, you need to have access to the following:
A database management system, such as Microsoft Access
A JDBC driver
If you don't have access to a DBMS, you can download the open source MySQL database at http://www.mysql.com. You can also download the JDBC driver for MySQL from this site.
You need to have the driver classes in your CLASSPATH statement in order to load the driver.
A simple example What's better than developing a small application to drill down into JDBC programming! Lets develop a small address book application that has the following features:
Lets you create the address book table
Lets you add an entry to the book
Lets you search for an entry in the book
This simple application will let us demonstrate the use of various JDBC classes and different types of SQL statements. It uses a database named "test_db" without any user ID or password. The database driver used is a type 4 driver for MySQL, however you can replace it with any other JDBC driver of your choice.
A word of caution: do not be overwhelmed by the lines of code below. Instead, concentrate on the core logic. Also, this is just a sample application to demonstrate the steps involved in JDBC programming. It's not designed for a production system.
Having said that, lets get started:
// AddressBookEntry.java
/** Class to represent an addressbook entry. */ public class AddressBookEntry {
/** The nickname. */ private String nickName; /** The name. */ private String name; /** The email. */ private String email;