Image8.gif (38059 bytes)      Java News Brief          
                                                                           DECEMBER   ISSUE                             Merry Christmas !


St. Louis:     12140 Woodcrest Executive Drive, Suite 250, St. Louis, MO 63141    Office: 314-579-0066
Tempe:        4500 S. Lakeshore Drive, Suite 359, Tempe, AZ 85282      Office: 480-752-0042   1-888-962-4624   Java.jpg (3634 bytes)

Headlines: 
 
Java Technical Insight of the Month   -  
Accessing Relational Data with JDBC
The Java News Brief Archive -
New
OCI Education Center - Open Enrollment Schedule
  - New  Evening Adv. Java Course
Why Java?  here are a few reasons...
                 
Java Technical Insight of the Month

Accessing Relational Data with JDBC
Weiqi Gao, Senior Software Engineer, Object Computing, Inc.

The JDBC API is a Java API for accessing relational (tabular) data, especially those stored in a relational database.   JDBC has been an integral part of Sun's Java Development Kit since 1.1, and is supported by virtually all relational database vendors.

Pieces of the puzzle
To use JDBC, several pieces of software must be installed:

  1. The Java Development Kit. The JDK contains the JDBC API interfaces as well as the JDBC driver manager. The JDBC API interfaces allows Java applications to access data in a uniform, vendor independent fashion.  The JDBC driver manager is responsible for finding and loading the correct JDBC driver based on the connection string.
  2. The JDBC driver for a particular brand of relational database. The JDBC driver contains classes that implement the standard JDBC interfaces.  The JDBC driver is responsible for actually communicating with the database and carrying out SQL commands and queries.  JDBC drivers can be implemented in four ways:
    1. JDBC-ODBC bridge plus ODBC driver: The JDK contains a JDBC-ODBC bridge which takes JDBC calls from a Java application and turns them into ODBC calls, utilizing the ODBC driver that is installed on the same machine.
    2. Native-API partly-Java driver: This kind of driver takes JDBC calls from a Java application and turns them into calls to the database vendor's native client access software that are installed on the same machine.
    3. JDBC-Net pure Java driver: This kind of driver takes JDBC calls from a Java application and turns them into a vendor independent net protocol.   At the other end of the network, the protocol is translated by a middleware server into a vendor specific protocol.
    4. Native-protocol pure Java driver: This kind of driver takes calls from Java applications and turns them into vendor specific protocols.

The JDBC API is easy to use
The JDBC API gives database access code an object-oriented feel.  Here's a snippet of very simple JDBC code that queries a database with an employee table for the last_name and hobby fields and prints out the result (we used the Connection, Statement, ResultSet classes):

import java.sql.*;

public class employee {
  public static void main(String[] args) {
    try {
      // Load the driver class
      Class.forName("postgresql.Driver");

      // Make a connection
      Connection conn = DriverManager.getConnection
        ("jdbc:postgresql://myhost/mydatabase", "myuserid", "mypassword");

      // Create a SQL statement
      Statement stmt = conn.createStatement();

      // Execute a query
      ResultSet rs = stmt.executeQuery
        ("select first_name, hobby from employee");

      // Fetch the data from the query result set
      while (rs.next()) {
        System.out.println("first_name: " + rs.getString(1));
        System.out.println("hobby: " + rs.getString(2));
      }
    } catch (Exception e) {
      System.out.println("Exception: " + e.getMessage());
    }
  }
}

Benefits of JDBC
Aside from being easy to use, the JDBC API also brings the following benefits:

  1. Wide availability. Since JDBC is included with the Java Platform, it is available everywhere Java is available.  This makes the Java application that uses the JDBC API portable to many platforms.
  2. Vendor independence. Since Java applications that use the JDBC API only use interfaces from the JDBC packages, the code has a high likelihood of being portable from one vendor's database to another.
  3. Multi-tiered applications. The JDBC API encourages Java applications to be designed into multiple tiers, separating business logic from presentation logic.  This aids to the scalability, reliability and maintainability of the application tremendously.
  4. Robustness, security, automatically downloadable code, and other Java pluses.  By virtue of being written in Java, the JDBC application automatically enjoys these benefits that Java offers.

JDBC is the basis for other technologies
The JDBC API offers the Java platform a standard way of accessing relational data. Many other technologies use the JDBC API as a low level tool to build higher level abstractions.  Enterprise JavaBeans (EJB) servers usually use JDBC API for their persistence mechanism.

JDBC 2.0
With the release of the Java 2 Platform comes the JDBC API 2.0. This new version of the JDBC API offers many more features in addition to the ones offered in JDBC API 1.x.   Most noticable are scrollable result sets, batch updates, and advanced data types.

The JDBC API 2.0 standard extension (javax.sql.*) offers JNDI support, connection pooling, and distributed transactions.

More information
The following web resource has more information about JDBC:  http://java.sun.com/products/jdbc/: (The official Sun Java JDBC site.)


The Java News Brief Archive - New

All issues of the JNB are now online for your convenience and can be accessed at  http://www.ociweb.com/jnb/index.html.  


OCI Education Center -  Open Enrollment Schedule 
Mesa & Tempe, Arizona - St. Louis ,Missouri


Click Course Titles (below)  for course description

Course Title Facility Dates Hours
CORBA Programming
St. Louis
Mesa
Jan 11-14
Mar 28-31
8:30-3:30
8:30-3:30
Advanced CORBA Programming using TAO (for Real-Time) St. Louis Feb 8-11 8:30-3:30
Object Oriented Concepts St. Louis Jan 19 8:30-3:30
Java Syntax for Non-C Programmers St. Louis Jan 20-21 8:30-3:30
Java Programming St. Louis
Mesa
Mesa
Feb 1-4
Feb 7-10
Mar 7-10
8:30-3:30
8:30-3:30
8:30-3:30
Advanced Java Programming Tempe

Mesa
Mesa
Jan 10,12,17,19,24,26
Jan 24-26
Feb 21-23
6:00-9:00 p.m.
8:30-3:30
8:30-3:30
Enterprise JavaBeans St. Louis Feb 23-25 8:30-3:30

For more information or to register email training.  


Why Java?  here are a few reasons...
Portability -
application logic, user interfaces, database access; ...not perfect portability but much better than other languages.
Support for Web-based Applications - applets for client-side processing; servlets for server-side processing
Built-in support for multi-threading
Built-in support for socket communication
Support of network protocols
Provides multiple ways of creating distributed applications -
sockets, RMI, CORBA, Enterprise Java Beans, Mobile Agents, Servlets and JavaSpaces
Object-Oriented - reuse; maintainability, extensibility
Automatic garbage-collection (memory management)
Productivity -
easier syntax than C++, no need to relink after each code change (speeds debugging)


Object Computing, Inc. is a Sun Authorized Java Center in St. Louis and a Member of the Object Management Group, OMG.  OCI provides Consulting, Education, and Product Development services to clients nation-wide.  For more information email info.

For employment opportunities at OCI call 1-888-962-4624 or email hr.

The Java News Brief is a monthly newsletter.  The purpose and intent of this publication is to advance Java, provide technical value, and to announce available OCI Java services.  If you would prefer to not receive this newsletter or would like to subscribe please email JNB and enter SUBSCRIBE or UNSUBSCRIBE within the Subject line.

Copyright (c) 1999.  Object Computing, Inc.   All rights reserved.   Java and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries.  Object Computing, Inc. is independent of Sun Microsystems, Inc.