Sample: Access a Large Object and Write It to a File

Objective
The objective of this sample is to demonstrate how to:

This sample can be run for DB2 access only.

The sample database you will use must be set up before you work with the sample. See Preparation for Samples for information.

Description
This sample does the following:

  1. Connects to the database.
  2. Uses the supplied employee number (specified by the user on the command line when the application is run) to access the row with that employee number and a photo_format value of ".gif"
  3. Creates a file called empno.gif, where empno is the supplied employee number.
  4. Outputs the large object, picture, to the new file.
  5. Disconnects from the database.

Generated Data Access Classes Used by this Sample
This sample uses the following generated classes and methods, as defined in the Data Access mapping, minisamp.dax:

Some of the methods listed are inherited from the Data Access class library.

Running the Sample
The executable for the sample is called gifget. Since for this sample, Data Access Builder generates code for two access methods (DB2 CLI and DB2 ESQL), a gifget executable is located in each of two corresponding directories: db2cli and db2esql (these are subdirectories of samples\database\minisamp).

To run the sample, enter the following on the command line of the appropriate directory, where number is an employee number for the picture you want to retrieve:

gifget number

If the sample fails because it could not connect to the database, enter a user ID and password that is valid for accessing the sample database, as shown:

giflist number userid password

The source code for the gifget executables is located in the samples\database\minisamp\source directory. If you make changes to the sample's source code, you must import the sample into an IDE project and rebuild it.

After running the sample, you can view the file that was created with any GIF viewer or internet browser. It contains the photo corresponding to the employee number you entered from the command line.

The Data Access Builder Mapping
The Data Access samples use a complex mapping, which is provided for you in a file called minisamp.dax. One minisamp.dax mapping file is provided in each of the two directories: db2cli and db2esql. If you want to see the mapping or generate the classes for it, import the sample into the IDE; in the Data Access Launch view, select the part and click Edit Part.

Hints on How to Create a Mapping for This Sample
Rather than using the mapping provided with the samples (minisamp.dax), you can create your own mapping that will work with this sample (but not necessarily the other samples). To create a mapping for this sample, follow these steps:

  1. In the IDE, created a new project, an executable target, and a new Data Access part. When you choose to add a Data Access part, the Data Acces SmartGuide will start up.
  2. To create the schema mapping in the SmartGuide pages, do the following steps:
    1. On the overview page of the SmartGuide, click Next>> to go to the next page.
    2. Select DB2 Driver and select the database SAMPLE.
    3. Select By selecting database tables or views for the method to create the schema mapping. Click Next>> to go to the next page.
    4. Select the desired database access method (DB2 CLI or DB2 ESQL). Click Next>> to go to the next page..
    5. Click Get Tables with Filter and when the list of tables is displayed, select EMP_PHOTO.
    6. Click Finish. You will return to the IDE.
  3. Build the part (The build process will automatically generate the classes for the mapping).



Data Access Builder
Data Access Builder Workflow
Large Object Support


Data Access Class Library and Generated Class Reference
Data Access Builder Samples
Preparation for Samples