Home > Articles > Programming > Java

Hooking Up with IBM DB2 Universal Database Version 8 Using Java

  • PrintPrint
  • Share ThisShare This
  • DiscussDiscuss
Close Window

Kulvir Singh BhogalGrant Hutchinson

Learn more…

Sorry, this author hasn't written any articles.

Sorry, this author doesn't have anything for sale.

Sorry, this author hasn't posted any blogs.

Integrated Solutions with DB2®

Like this article? We recommend
Integrated Solutions with DB2®

Need a jump start on using DB2 with JDBC technology? Database programming with JDBC lets Java programmers interact programmatically with database systems. Kulvir Bhogal and Grant Hutchison discuss the subject of programming with JDBC when the target database is the IBM DB2 universal database.

The relational database serves as a location to persist data for many applications. Java programmers commonly use JDBC to interact with backend databases. This article shows you how to set up your environment to write Java programs that interact with IBM DB2 Universal Database Version 8. You will notice that there are different approaches to connecting to DB2 that require different drivers, software, and syntax. In this article, we'll shed light on the subject so you can evaluate which approach is appropriate for you getting your Java program "hooked up" to DB2.

DB2 Universal Database Version 8.1 fully supports the JDBC v2.1 specification. It also supports portions of the JDBC 3.0 specification. Usage on the new JDBC 3.0 features of the driver requires a JDK 1.4 environment.

DB2 Version 8 provides support for four different JDBC driver architectures, named Type 1, Type 2, Type 3, and Type 4. In this article, we'll focus on the Type 2 and Type 4 drivers because they are the drivers that you will most likely use to enable your Java applications to talk to DB2.

Something to Hook Up to

Because we plan to show how to use Java to interact with a database, we need a database to play with. Let's dedicate some time to create one here. Suppose that you have a user on your DB2 server with the name of db2admin and a password of db2admin. Let's create a small database on our database server, associating a name to a phone number. We'll call our database phonedb. Using the DB2 command line processor, enter the following command:

db2 => create database phonedb

Next, we connect to the database:

db2 => connect to phonedb user db2admin using db2admin

We create our table using this command:

db2 => create table phonenumbers (name varchar(60) not null primary key, phonenumber varchar(13) not null)

Finally, let's insert a couple of records:

db2 => insert into phonenumbers values('Jack Price','(888)888-8888')

db2 => insert into phonenumbers values('David Jones',(555)555-5555')
  • Share ThisShare This
  • Your Account

Discussions

Good working.
Posted Jun 3, 2008 08:07 AM by ankaranakliyat
0 Replies
Good working.
Posted Jun 3, 2008 08:06 AM by ankaranakliyat
0 Replies
Good working.
Posted Jun 3, 2008 08:06 AM by ankaranakliyat
0 Replies

Make a New Comment

You must log in in order to post a comment.

Related Resources

Jennifer  BortelWin FREE iPhone Developer Books and Videos- Introducing @InformIT Giveaways
By Jennifer Bortel on February 5, 2010 No Comments

Apples’s recent iPad announcement made our hearts flutter so we couldn’t resist making an announcement of our own!

Today marks the first ever @InformIT Giveaway!

We’ll regularly post a video like this one profiling spectacular prizes we’re giving away—from books and videos to T-shirts and other exciting stuff. Check out the video below to see the giveaways for today, and then scroll down for more prize details and instructions on how to win them!

Dustin Sullivan"Every OSX developer should have this book on their desk."
By Dustin Sullivan on February 1, 2010 No Comments

That was the sentence Mike Riley ended his recent Dr Dobb's CodeTalk review of Cocoa Programming Developer's Handbook with.

David ChisnallCocoa Tip of the Day, 1/29/10
By David Chisnall on January 29, 2010 No Comments

Don't ignore old versions of OS X.

See All Related Blogs

Informit Network