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

Danny KalevMinutes from the October 2009 Meeting
By Danny Kalev on Yesterday No Comments

The minutes from the Santa Cruz (October 2009) meeting are available here. Even if you're not a language layer at heart, I encourage you to read them.

Danny KalevA Reader's Opinion on Attributes
By Danny Kalev on October 20, 2009 No Comments

In August I dedicated a series to the debate about C++0x attributes. I believe that it covered the subject in a balanced and detailed way, but I keep getting complaints from C++ users who don't like attributes for various reasons. Here's a recent email I received from a Polish C++ programmer. While it  doesn't represent my opinion about attributes -- I'm rather neutral about this feature and consider it a "solution waiting for a problem" -- but it suggests that attributes are still a highly controversial issue that will haunt C++ for a long time. The email is quoted here with minor edits that and as usual, with all private details removed.

Danny KalevFollowup: The Web 2.0 Guy I Ain't
By Danny Kalev on October 16, 2009 1 Comment

Almost a year ago, I posted here The Web 2.0 Guy I Ain't. People wonder whether I still resist all those Web 2.0 features and technologies at the end of 2009.

See All Related Blogs

Informit Network