XML - Managing Data Exchange/XML and JDBC

From Wikibooks, open books for an open world
Jump to navigation Jump to search

XML - Managing Data Exchange
Related Topics
Computer Science Home
Library and Information Science Home
Markup Languages
Get Involved
To do list
Contributors list
Contributing to Wikibooks
Previous Chapter Next Chapter
Exchanger XML Lite XForms


[edit | edit source]

ODBC is the acronym for the oft used API Open Database Connectivity. Many applications and application programmers use ODBC in order to access relational databases, such as SQL and Microsoft Access, and to manipulate the data within the databases. Specifically, JDBC (Java Database Connectivity), which is based on ODBC, is the API used by applications developed in Java to perform these various tasks. Moreover, JDBC is now capable of handling advanced datatypes in SQL which in turn becomes useful when dealing with XML. Also, JDBC has within it the ability to actually create XML data. Furthermore, the use of JAXP (Java API for XML Processing) along with JDBC provides yet another way of manipulating and using relational databases and XML. In any event, there are multiple ways to use the JDBC API with XML.

JDBC and XML Documents

[edit | edit source]

Many Java Applications written today will more than likely interact with an SQL database (or a relational database, but for the sake of uniformity, we will work with SQL.) Depending on the intent of the application, there may be the case of actually storing an XML document for display or for manipulation. Whatever the case, JDBC now supports all datatypes defined in the SQL:1999 specification. One of theses datatypes is the CLOB (character large object) datatype. This datatype is perfect for storing XML documents. This is one way XML and the JDBC API works with each other.

JDBC and XML Production

[edit | edit source]

One of the more interesting things about JDBC is that it can be used to gather MetaData. Meta-data is nothing more than data about data. From an XML standpoint, this is very useful because we can create XML data on the fly with nothing more than a table name. The class that makes this possible is java.sql.ResultSetMetaData. Consequently this class is a part of the JDBC API.


[edit | edit source]

Another intriguing way of dealing with XML objects is within the JAXP (Java API for XML Processing). JAXP and JDBC together provide an infrastructure for developing applications using XML and SQL.

Whenever XML instances in applications are dealt with, an XML parser is a good tool to use. The XML parser turns the XML document into an object or something the application can uses. Specifically, Document Object Model (DOM) takes and XML instance and converts it into a tree. This specific parser can be found in the JAXP API. You may then store the parsed object in an SQL database for future use. This may open up many ideas of how one may use JAXP and JDBC together when an issue presents itself of dealing with XML and SQL.


[edit | edit source]