Introduction
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.
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.
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:
- A text editor: XML and Java source files are simply text. To create and read them, a text editor is all you need.
- A Java environment such as the Java 2TM SDK, which is available at http://java.sun.com/j2se/1.3/.
- Java API for XML Processing: Also known as JAXP 1.1, this is the reference implementation that Sun provides. You can download JAXP from http://java.sun.com/xml/xml_jaxp.html.
- Any database that understands SQL, as long as you have an ODBC or JDBC driver. You can find a searchable list of more than 150 JDBC drivers at http://industry.java.sun.com/products/jdbc/drivers. (If you have an ODBC driver, you can skip this step, and use The JBDC-ODBC bridge.) This tutorial uses JDataConnect, available at http://www.jnetdirect.com/products.php?op=jdataconnect.
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 monospacefont. 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
monospacefont presents file and path names. - Throughout this tutorial, code segments irrelevant to the discussion have been omitted and replaced with ellipses (
...)


