About 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
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.
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.
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
After this, the
Clob advanced datatypes are introduced along with several examples that demonstrate their use.
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
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
DataSourceobject, 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.