JDBC and Java DB - dummies

By Barry Burd

Some programmers learning Java say. “We don’t need to make any cute little characters fly across the screen. No blinking buttons for us. We need to access databases. Yup, just show us how to write Java programs that talk to databases.”

So here it is, folks — Java Database Connectivity. Some people’s toughest problem was connecting to a database. They have written all the Java code. (Or copied all the Java code from some book.) The Java part is easy to them. The hard part is getting their code to find the database on the system.

Part of the problem was that the way you get your code to talk to the database depends on the kind of system you have and the kind of database that you’re running on your system. The books can’t be too specific on all the details because the details (having nothing to do with Java) vary from one reader’s computer to another.

Fortunately, the Java Development Kit (JDK) comes with its own built-in database — Java DB. Based on the Apache Derby database, Java DB is secure, lightweight, and standards-based. Java DB runs seamlessly along with the rest of the Java JDK. The Java gurus introduced Java DB with the release of Java 6.

Java DB makes life easier by providing a common database that all readers can use. The database is freely available, and it requires no setup.

And what if you don’t use Java DB? What if all your data is stored in other kinds of databases; namely, MySQL, PostgreSQL, SQLite, Oracle, Microsoft Access, DB2, or almost any other database? Then Java has a solution for you! The Java Database Connectivity (JDBC) classes provide common access to most database management systems. Just get a driver for your favorite vendor’s system, customize two lines of code in each Java example, and you’re ready to run the code.