Home arrow Java arrow Page 2 - Reading and Writing Data Using JDBC and XML

Reading and Writing Data Using JDBC and XML

For those who want to delve deeply into Java, this article explores Java Database Connectivity (JDBC), a class library that connects Java programs to relational databases. The first of three parts, it is excerpted from chapter 20 of the book Sams Teach Yourself Java 2 in 21 Days, 4th Edition, written by Rogers Cadenhead and Laura Lemay (Sams; ISBN: 0672326280).

Author Info:
By: Sams Publishing
Rating: 4 stars4 stars4 stars4 stars4 stars / 9
June 08, 2006
  1. · Reading and Writing Data Using JDBC and XML
  2. · Database Drivers
  3. · Connecting to an ODBC Data Source
  4. · Retrieving Data from a Database Using SQL
  5. · Writing Data to a Database Using SQL

print this article

Reading and Writing Data Using JDBC and XML - Database Drivers
(Page 2 of 5 )

Java programs that use JDBC classes can follow the familiar programming model of issuing SQL statements and processing the resulting data. The format of the database and the platform it was prepared on don't matter.

This platform- and database-independence is made possible by a driver manager. The classes of the JDBC class library are largely dependent on driver managers, which keep track of the drivers required to access database records. You'll need a different driver for each database format that's used in a program, and sometimes you might need several drivers for versions of the same format.

JDBC also includes a driver that bridges JDBC and another database-connectivity standard, ODBC.

The JDBC-ODBC Bridge

ODBC, Microsoft's common interface for accessing SQL databases, is managed on a Windows system by the ODBC Data Source Administrator.

This is run from the Control Panel on a Windows system; to get there on most versions of Windows, click Start, Settings, Control Panel, ODBC Data Sources. On Windows XP, choose Start, Control Panel, Performances and Maintenance, Administrative Tools, Data Sources (ODBC).

The administrator adds ODBC drivers, configures drivers to work with specific database files, and logs SQL use. Figure 20.1 shows the ODBC Data Source Administrator on a Windows system.

Figure 20.1  The ODBC Data Source Administrator on a Windows XP system.

In Figure 20.1, the Drivers tabbed dialog box lists all the ODBC drivers present on the system. Many of the drivers are specific to a database company's format, such as the Microsoft Access Driver.

The JDBC-ODBC bridge allows JDBC drivers to be used as ODBC drivers by converting JDBC method calls into ODBC function calls.

Using the JDBC-ODBC bridge requires three things:

  • The JDBC-ODBC bridge driver included with Java 2: sun.jdbc.odbc.JdbcOdbcDriver

  • An ODBC driver

  • An ODBC data source that has been associated with the driver using software such as the ODBC Data Source Administrator

ODBC data sources can be set up from within some database programs. For example, when a new database file is created in Lotus Approach, users have the option of associating it with an ODBC driver.

All ODBC data sources must be given short descriptive names. The name is used inside Java programs when a connection is made to the database that the source refers to.

On a Windows system, after an ODBC driver is selected and the database is created, they show up in the ODBC Data Source Administrator. Figure 20.2 shows an example of this for a data source named WorldEnergy.

Figure 20.2  A listing of data sources in the ODBC Data Sources Administrator.

The data source WorldEnergy is associated with a Microsoft Access driver, according to Figure 20.2.

Note - Most Windows database programs include one or more ODBC drivers that correspond to the format. Microsoft Access includes ODBC drivers that can be used to connect to an Access database file.

blog comments powered by Disqus

- Java Too Insecure, Says Microsoft Researcher
- Google Beats Oracle in Java Ruling
- Deploying Multiple Java Applets as One
- Deploying Java Applets
- Understanding Deployment Frameworks
- Database Programming in Java Using JDBC
- Extension Interfaces and SAX
- Entities, Handlers and SAX
- Advanced SAX
- Conversions and Java Print Streams
- Formatters and Java Print Streams
- Java Print Streams
- Wildcards, Arrays, and Generics in Java
- Wildcards and Generic Methods in Java
- Finishing the Project: Java Web Development ...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials