Java
  Home arrow Java arrow Reading and Writing Data Using JDBC and XM...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVA

Reading and Writing Data Using JDBC and XML
By: Sams Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 2 stars2 stars2 stars2 stars2 stars / 4
    2006-06-08

    Table of Contents:
  • Reading and Writing Data Using JDBC and XML
  • Database Drivers
  • Connecting to an ODBC Data Source
  • Retrieving Data from a Database Using SQL
  • Writing Data to a Database Using SQL

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Reading and Writing Data Using JDBC and XML


    (Page 1 of 5 )

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

    Almost all Java programs deal with data in some way. You have used primitive types, objects, arrays, linked lists, and other data structures up to this point.

    Today, you will work with data in a more sophisticated way by exploring Java Database Connectivity (JDBC), a class library that connects Java programs to relational databases, and Extensible Markup Language (XML), a formatting standard that enables data to be completely portable.

    You'll explore JDBC and XML in the following ways:

    • Using JDBC drivers to work with different relational databases

    • Accessing a database with Structured Query Language (SQL)

    • Reading records from a database using SQL and JDBC

    • Adding records to a database using SQL and JDBC

    • Representing data as XML

    • Discovering why XML is a useful way to store data

    • Using XML to create a new data format

    • Reading and writing XML data

    Java Database Connectivity

    Java Database Connectivity (JDBC) is a set of classes that can be used to develop client/server applications that work with databases developed by Microsoft, Sybase, Oracle, Informix, and other sources.

    With JDBC, you can use the same methods and classes in Java programs to read and write records and perform other kinds of database access. A class called a driver acts as a bridge to the database source—there are drivers for each of the popular databases.

    Client/server software connects a user of information with a provider of that information, and it's one of the most commonplace forms of programming. You use it every time you surf the Web: A Web browser client requests pages, image files, and other documents using a Uniform Resource Locator, or URL. Web servers provide the requested information, if it can be found, for the client.

    One of the biggest obstacles faced by database programmers is the wide variety of database formats in use, each with its own proprietary method of accessing data.

    To simplify using relational database programs, a standard language called SQL (Structured Query Language) has been introduced. This language supplants the need to learn different database-querying languages for each database format.

    In database programming, a request for records in a database is called a query. Using SQL, you can send complex queries to a database and get the records you're looking for in any order you specify.

    Consider the example of a database programmer at a student loan company who has been asked to prepare a report on the most delinquent loan recipients. The programmer could use SQL to query a database for all records in which the last payment was more than 180 days ago and the amount due is more than $0.00. SQL also can be used to control the order in which records are returned, so the programmer can get the records in the order of Social Security number, recipient name, amount owed, or another field in the loan database.

    All this is possible with SQL—the programmer doesn't need any of the proprietary languages associated with popular database formats.


    Caution - SQL is strongly supported by many database formats, so in theory you should be able to use the same SQL commands for each database tool that supports the language. However, you still might need to learn some idiosyncrasies of a specific database format when accessing it through SQL.


    SQL is the industry-standard approach to accessing relational databases. JDBC supports SQL, enabling developers to use a wide range of database formats without knowing the specifics of the underlying database. JDBC also supports the use of database queries specific to a database format.

    The JDBC class library's approach to accessing databases with SQL is comparable to existing database-development techniques, so interacting with an SQL database by using JDBC isn't much different than using traditional database tools. Java programmers who already have some database experience can hit the ground running with JDBC.

    The JDBC library includes classes for each of the tasks commonly associated with database usage:

    • Making a connection to a database

    • Creating a statement using SQL

    • Executing that SQL query in the database

    • Viewing the resulting records

    These JDBC classes are all part of the java.sql package in Java 2.

    More Java Articles
    More By Sams Publishing


       · This article is an excerpt from the book "Sams Teach Yourself Java 2 in 21 Days, 4th...
     

    Buy this book now. This article 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). Check it out today at your favorite bookstore. Buy this book now.

    JAVA ARTICLES

    - 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 ...
    - Generics and Limitations in Java
    - Getting Started with Java Web Development in...






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
    Stay green...Green IT