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 developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

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]

Managing database connections 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 introduces the different concepts involved in establishing and managing a database connection from within a Java application using Java Database Connection (JDBC). It is targeted primarily at developers who want to understand what is "going on under the hood" when using a database from within a Java application.

Date:  13 Nov 2001
Level:  Introductory PDF:  A4 and Letter (149 KB | 31 pages)Get Adobe® Reader®

Activity:  12106 views
Comments:  

About this tutorial

Should I take this tutorial?

This tutorial introduces the different concepts involved in establishing and managing a database connection from within a Java application using Java Database Connection (JDBC). It is targeted primarily at developers who want to understand what is "going on under the hood" when using a database from within a Java application.

This tutorial assumes familiarity with the Java programming language. The links in Resources include referrals to additional information on both JDBC and specific databases.


What is this tutorial about?

This tutorial demonstrates how to connect to a database using JDBC. While seemingly innocuous, this subject is actually a stumbling block for both newcomers and veterans alike. This tutorial will discuss how a Java application inside a JVM discovers and communicates with a database, starting with the traditional JDBC driver and DriverManager objects. After several examples that demonstrate the four different types of JDBC drivers, the tutorial moves on to discuss DataSource objects that use JNDI. A discussion of JNDI, and how to bind, use, rebind, and delete the DataSource object is also included. Finally, the concept of a connection pool, and specifically PooledConnection objects are introduced and demonstrated. The tutorial concludes with a discussion of tuning issues that are often overlooked when developing database connectivity applications.


Tools

While the tutorial provides numerous code snippets to reflect concepts and methods described in the text, most people learn better by actually working through the examples. To work through the examples, you will need to have the following tools 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 they hide too many of the details.

  • A Java development environment, such as the Java2 SDK, which is available at http://java.sun.com/j2se/1.4/. The Java2 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.

  • A JDBC driver: Because the JDBC API is predominantly composed of interfaces, you need to obtain an actual JDBC driver implementation in order to actually connect to a database using JDBC. If your database (or your wallet) does not allow the use of JDBC, you can always use the JDBC-ODBC bridge driver to connect to any database (or data source) that supports the ODBC protocol.

1 of 10 | Next

Comments



Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

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

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).