DB Access Class Library for COBOL V1.0 API Reference - Microsoft(R) Windows(R) - - Microsoft(R) Windows NT(R) - - Microsoft(R) Windows(R) 2000 -
Contents Index PreviousNext

UpChapter 4 Examples of Using the DB Access Class Library
Up4.1 Use a Recordset

4.1.2 Connect to a database


To connect to a database, proceed as follows:


  1. Define the class and symbolic constants.

    Define the class to use in the repository paragraph of the configuration section, and a library of symbolic constants to use in the program in the special-names paragraph.

     CONFIGURATION SECTION.
     REPOSITORY.
         CLASS FJDB-SESSION
         CLASS FJDB-DATABASE
         CLASS FJDB-ERROR.
     SPECIAL-NAMES.
         SYMBOLIC CONSTANT
         COPY FJDBOPT.
        .
    
  2. Define variables.

    Define the variables to use in the program.

      WORKING-STORAGE  SECTION.
     *Define object variables
      01  SESSION-A     USAGE OBJECT REFERENCE FJDB-SESSION.
      01  DATABASE-A    USAGE OBJECT REFERENCE FJDB-DATABASE.
      01  ERROR-A       USAGE OBJECT REFERENCE FJDB-ERROR.
     *Define data setup variables
      01  DSN          PIC X(10).
      01  UID          PIC X(10).
      01  PWD          PIC X(10).
      01  SCM          PIC X(10).
      01  DB-OPT       PIC S9(9) COMP-5.
     *Define the return value variable
      01  RET-CODE     PIC S9(9) COMP-5.
    
  3. Load the variables with values.

    Load the variables with required information before issuing an OPEN-DATABSE method.

         MOVE "DB01"    TO DSN.     *>Database environment name
         MOVE "YODA"    TO UID.     *>User ID
         MOVE "YODA"    TO PWD.     *>Password
         MOVE "GENERAL" TO SCM.     *>Default Schema
         MOVE  FJDB-SCDBOPT-DEFAULT TO DB-OPT. *> Option
    
  4. Connect to a database.

    Make a connection to a database using an OPEN-DATABASE method.
    An object of the FJDB-DATABASE class is created.

         INVOKE SESSION-A "OPEN-DATABASE" USING DSN UID PWD SCM 
                                                DB-OPT DATABASE-A
                                                RETURNING RET-CODE.
    

Contents Index PreviousNext

All Rights Reserved, Copyright (C) FUJITSU LIMITED 1998-2000