To begin, let's log on.
In the old days, connecting to a database was more or less a matter of opening a few files. These days, the complications of networking, RDBMSs, client/server computing, and a host of other considerations have made database connection a major hurdle to overcome in building applications. DBTools.h++ simplifies the process.
NOTE: With DBTools.h++, you establish a database connection by requesting an RWDBDatabase instance from the RWDBManager.
DBTools.h++ is designed to provide a single, global instance of the class RWDBManager. RWDBManager is responsible for providing your applications with correctly typed RWDBDatabase objects, based upon parameters provided to its static database() member function.
The following example shows how to establish connectivity using DBTools.h++. Unlike the code fragments you have seen so far, this is a complete program. After changing the parameters in the database() call to fit your system, you can and should compile and run this program before you attempt anything more ambitious. Remember that you must first establish connectivity without DBTools.h++, or this program may not work.
// Example Program 1 - Establishing connectivity #include <rw/rstream.h> #include <rw/db/db.h> #include <rw/db/dbmgr.h> int main() { RWDBDatabase myDbase = RWDBManager::database( "libctl0d.so", // access library name //1 "sybase_host", // server name //2 "dbxx", // user name //3 "demodb", // password //4 "DEMO_DB" // database name //5 ); if (myDbase.isValid()) { cout << "Connected!" << endl; } else { cout << myDbase.status().message() << endl; } return 0; }
Let's look at the parameters for the RWDBManager::database() call:
It is also possible to establish multiple login sessions to a database. The information you provide in the RWDBManager::database() call is retained in each database object, so that you don't have to repeat it every time.
When you can successfully run the example program above and obtain an RWDBDatabase whose isValid() member function returns true, you can be confident that:
The access library you specified has been located.
An RWDBConnection object has been successfully instantiated and reserved by the database object for use as a default connection.
In other words, your database connectivity has been established, and you are ready to continue.
©Copyright 2000, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.