Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Advanced database operations with JDBC

Robert Brunner (rjbrunner@pacbell.net), Astrophysicist , California Institute of Technology
Robert J. Brunner
Robert J. Brunner is an astrophysicist by day and a computer hacker by night. His principal employer is the California Institute of Technology, where he works on knowledge extraction and data-mining from large, highly distributed astronomical databases. He has provided consulting to scientific data centers around the world, provided Java and XML training to a variety of groups, and is currently working on the book Enterprise Java Database Programming which will be published by Addison Wesley in 2002.

Summary:  This tutorial is designed to introduce you to several advanced database operations, including stored procedures and advanced datatypes, that can be performed by a Java application using JDBC.

Date:  19 Nov 2001
Level:  Intermediate PDF:  A4 and Letter (236 KB | 25 pages)Get Adobe® Reader®

Activity:  12027 views
Comments:  

About this tutorial

Should I take this tutorial?

This tutorial is designed to introduce you to several advanced database operations, including stored procedures and advanced datatypes, that can be performed by a Java application using JDBC. The example code in this tutorial was written to work with DB2 Universal Database 7.2, but modifying the code to work with other databases is trivial due to the use of a DataSource object.

This tutorial assumes that you are already familiar with the Java programming language and, to some extent, JDBC. To fully leverage some of the material contained in this tutorial we recommend that you complete the tutorial Managing database connections with JDBC . The links in Resources include referrals to additional information on JDBC.


What is this tutorial about?

This tutorial demonstrates how to perform advanced operations with a database using JDBC. It focuses on more advanced database functionality, including database design, prepared statements, stored procedures, and advanced datatypes.

The tutorial begins with a discussion of the design of a fictitious message board system. Topics include creating the tables, populating them with data, and using a DataSource object to ensure maximum portability between databases.

Next, the PreparedStatement object is introduced along with examples to show how it simplifies certain types of application development, including the population of tables.

The topic of stored procedures is then broached, from how to create Java stored procedures, to the proper handling of stored procedures from an application using the JDBC CallableStatement.

After this, the Blob and Clob advanced datatypes are introduced along with several examples that demonstrate their use.


Tools

Numerous code snippets are provided to help you make the transition from theory to practical use. To actively work through these examples, the following tools need to be installed and working correctly:

  • A text editor: Java source files are simply text, so to create and read them, all you need is a text editor. If you have access to a Java IDE, you can also use it, but sometimes IDEs hide too many of the details.

  • A Java development environment, such as the Java 2 SDK, which is available at http://java.sun.com/j2se/1.4/. The Java 2 SDK, Standard Edition version 1.4, includes the JDBC standard extensions as well as JNDI, which are both necessary for some of the latter examples in the book.

  • An SQL-compliant database: The examples in this tutorial use a wide variety of different databases to help demonstrate how database independent JDBC programming can be. Resources contains links to more information on both JDBC and databases. In particular, the examples in this tutorial have been tested with DB2 running on a Windows 2000 server, but because they are written using a DataSource object, they should easily convert to other databases.

  • A JDBC driver: Because the JDBC API is predominantly composed of interfaces, you need to obtain an actual JDBC driver implementation to make the examples in this tutorial actually work. The examples in this tutorial use advanced JDBC functionality, and, therefore, they require an advanced JDBC driver. Most database and JDBC driver vendors will supply you with an evaluation version of a particular JDBC driver.

1 of 9 | Next

Comments



static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Java technology
ArticleID=131804
TutorialTitle=Advanced database operations with JDBC
publish-date=11192001
author1-email=rjbrunner@pacbell.net
author1-email-cc=jaloi@us.ibm.com