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]

Using JDBC to insert data from XML into a database

XML data can find a permanent home

Photo of Nicholas Chase
Nicholas Chase has been involved in Web site development for companies including Lucent Technologies, Sun Microsystems, Oracle Corporation, and the Tampa Bay Buccaneers. Nick has been a high school physics teacher, a low-level radioactive waste facility manager, an online science fiction magazine editor, a multimedia engineer, and an Oracle instructor. More recently, he was the Chief Technology Officer of Site Dynamics Interactive Communications in Clearwater, Florida. He is the author of three books on Web development, including Java and XML From Scratch (Que). He loves to hear from readers and can be reached at nicholas@nicholaschase.com.

Summary:  As flexible as XML is with regards to storing data, it is perfect for holding data that is ultimately destined for a database. This tutorial will show you how to access a database using the JDBC API and use SQL to insert data that has been retrieved from an XML file using a predetermined mapping. It also demonstrates the use of updatable ResultSets.

Date:  03 Oct 2001
Level:  Intermediate PDF:  A4 and Letter (111 KB | 32 pages)Get Adobe® Reader®

Activity:  10206 views
Comments:  

Introduction

Should I take this tutorial?

This tutorial is designed to assist Java developers who need to extract information from an XML document and enter it into a database.

The tutorial assumes that you are already familiar with the Java and XML languages in general, and the Document Object Model (DOM) in particular. You should be familiar with Java programming, but prior JDBC knowledge is not required to master the techniques described in this tutorial. The tutorial briefly covers the basics of SQL. GUI programming knowledge is not necessary because application input/output is handled from the command line. The links in Resources include referrals to tutorials on XML and DOM basics and a detailed SQL backgrounder.

What is this tutorial about?

This tutorial demonstrates a method for retrieving XML data and inserting it into a database using the example of orders stored in an XML file. A second XML file is used to determine which elements in the orders file correspond to which tables and columns in the database.

The JDBC API is a vendor-independent method for accessing databases using the Java language. This tutorial explains how to instantiate and use a JDBC driver to connect to a database in order to store information. It also explains the basics of the required SQL and how execute it using JDBC methods. Finally, this tutorial demonstrates techniques for updating data directly through the ResultSet for a query.


Tools

This tutorial will help you understand the topic even if you only read through the examples without trying them out. If you do want to try the examples as you go through the tutorial, however, make sure you have the following tools installed and working correctly:


Conventions used in this tutorial

There are several conventions used in this tutorial to reinforce the material at hand:

  • Text that needs to be typed is displayed in a bold monospace font. In some code examples, bold is used to draw attention to a tag or element being referenced in the accompanying text.
  • Emphasis/Italics is used to draw attention to windows, dialog boxes, and feature names.
  • A monospace font presents file and path names.
  • Throughout this tutorial, code segments irrelevant to the discussion have been omitted and replaced with ellipses (...)

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=XML
ArticleID=138240
TutorialTitle=Using JDBC to insert data from XML into a database
publish-date=10032001
author1-email=nicholas@nicholaschase.com
author1-email-cc=

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).

Try IBM PureSystems. No charge.