ActiveX Data Objects

The balance of this chapter deals with the use of Microsoft ActiveX Data Objects (ADO) and the relationship of ADO to Visual J Plus Plus and SQL.

What is ADO?

As I mentioned earlier, the internal data structure might (and in fact, generally does) vary from one database to another. This isn't a problem when you are entering commands from a SQL tool, but it's a problem when accessing these databases from Visual J Plus Plus.

As part of the Windows Open System Architecture (WOSA), Microsoft defined the Open Database Connectivity (ODBC) app program interface (API). The current 32-bit version, ODBC32, replaces the older 16-bit version.

ODBC32 provides an API that database vendors implement by means of ODBC drivers specific to their particular database. Your program uses this API to call the ODBC32 Driver Manager, a dynamic-link library that passes the calls to the appropriate driver. The driver, in turn, interacts with the database using SQL.

As a Windows standard, there is an ODBC32 driver for almost every common database in existence. Unfortunately, the ODBC32 API is somewhat complicated and is not optimized for Visual J Plus Plus. To address the ODBC32 complexity problem, version 6 of the development environment for the Microsoft Visual Studio languages introduces the ADO 2.0 interface. This interface is an API that is ideal for object-oriented languages like Visual J Plus Plus: it has fewer classes and a simpler interface than ODBC32. Since ADO is built on top of the 32-bit version of ODBC, the ADO classes can be used with any database for which an ODBC32 driver exists.

Visual J Plus Plus v6 also contains a number of Toolbox tools for adding database interaction capabilities to your app. While these tools certainly simplify the job, you still must have some knowledge of ADO to develop apps that use databases.

Approaches to ADO

In this chapter, we'll cover three basic approaches to writing ADO apps: writing the app manually; using the app Wizard; and using the Toolbox data tools.

I have always felt that a person needs to know how to multiply by hand before using a calculator. With that in mind, we'll begin by manually creating a simple example app that accesses a small database by means of ADO. From there, we'll move to an app built by the fully automatic but inflexible app Wizard. The chapter wraps up with a demonstration of a slightly more complicated but much more flexible approach. We'll use the Toolbox data tools and learn how to access databases on PCs connected to your PC by means of a LAN. Comments