Virtual Tables, External Data, and Aggregates,
Page 3 of 6


[top]
[prev]
[next]

Road Map
Glossary
Index for This Book
Documentation Top
Global Index

External Virtual Tables and Bulk Import

Cloudscape provides a construct for presenting external data—from a flat file, from another vendor’s database, from a news feed—as a virtual table to an SQL-J SELECT statement. External data presented in this way constitutes an external virtual table that can be used within the scope of an SQL-J statement in the same way as other virtual or derived tables.

An external virtual table is created by an instance of any class that fulfills the requirements of Cloudscape’s virtual table interface (VTI):

  • It implements the java.sql.ResultSet interface.
    It is up to the programmer to determine what work needs to be done in order to return the ResultSetMetaData.
  • The parameters to the VTI constructor must all be constants to ensure that the result set description can be determined during compilation.

Optionally, the class:

  • provides the static method public static java.sql.ResultSetMetaData getResultSetMetaData(parameterList)
    for which the parameterList signature is the same as for the constructor for that object that appears in the SQL-J statement.
  • implements COM.cloudscape.vti.VTICosting

Cloudscape provides a class that fulfills these requirements, COM.cloudscape.tools.FileImport. This class can present data from a flat text file to an SQL-J as an external virtual table. However, you can write any class that fulfills the above requirements to “build your own” external virtual table. Later in this chapter, you will look at another class that fulfills those requirements to provide a gateway to any vendor’s database that has a JDBC driver.

TASK: Import Data from a Flat File Using the Built-In Utility

  1. Close the connection to the toursDB database from Cloudview.
  2. Open a connection to the HelloWorldDB database as described in “Connect to HelloWorldDB”.
  3. Create a new table called WorldCupStatistics with the following columns:
    • RANK, SMALLINT
    • TEAM, VARCHAR(20)
    • P, SMALLINT
    • W, SMALLINT
    • D, SMALLINT
    • L, SMALLINT,
    • PTS, SMALLINT
    • PERCENT, DECIMAL(3,1)

      You can use Cloudview to create the table, following the instructions for table creation in “Create the Sayings Table”. Or, if you like, you can just cut and paste the following SQL-J statement into the SQL window:

      CREATE TABLE WorldCupStatistics
         (Rank SMALLINT,
          Team VARCHAR(20),
          P SMALLINT,
          W SMALLINT,
          D SMALLINT,
          L SMALLINT,
          Pts SMALLINT,
          Percent DECIMAL(3,1));

  4. After you create the table, select its icon.
  5. Choose Edit->Import.
  6. Navigate to the your_tutorial_home directory. Select wc_stat.dat.
  7. Click Open. If you are working on a PC platform, skip to step 9.
  8. If you are working on a non-PC platform only, select the Advanced tab and select CR-LF as the record separator. (For users on PC platforms, CR-LF is assumed to be the default record separator.) Click Save to save the control file, which specifies non-default settings, for the import. Type mycontro.ctl as the name of your control file. Click Save. The file should be saved into the system directory.
  9. Click OK.

    Data is imported into the file.

  10. Examine the data by clicking the Data tab.

TASK: Import Data from a Flat File Using an SQL-J Statement

  1. Delete all the data from the WorldCupStatistics table using the following statement in the SQL window:

    DELETE
    FROM WorldCupStatistics

  2. Click the lightning bolt to execute.
  3. Import data from the same file with one of the following SQL-J statements, substituting the path to the your_tutorial_home directory where indicated.

    Users on PC platforms should use this statement:

    INSERT INTO WorldCupStatistics
    SELECT * from NEW FileImport(
        'YOURTUTORIALHOME/wc_stat.dat') AS myExternalData;

    Users on non-PC platforms should use this statement (which specifies a control file):

    INSERT INTO WorldCupStatistics
    SELECT * from NEW COM.cloudscape.tools.FileImport(
        'YOURTUTORIALHOME/wc_stat.dat',
        'mycontrol.ctl') AS myExternalData;

NOTE: Do not split the string containing the file URL into two lines. Do not use a relative path to the directory.

Data is imported into the file.

  1. Examine the data by selecting the WorldCupStatistics table icon and clicking the Data tab.
  2. Exit Cloudview.

NOTE: Cloudscape also provides an export utility. In addition, Cloudview allows you to use alternate file formats for import and export. See the Cloudview on-line help for more information.

[top]
[prev]
[next]


Cloudscape Version 3.0
For technical support, go to: www.cloudscape.com and click Support.
Copyright © 1998 and 1999 Cloudscape, Inc. All rights reserved.