Creating and accessing tables
The following examples illustrate how to create a table named PEOPLE, which store the name, address, and phone number of a customer. This example contains three blocks of code:
The first snippet creates a CLI connection to a local DB2 database. Modify the code for other databases in the following manner:
a. Oracle
1. Change #AbtIbmCliDatabaseManager to #AbtOracle10DatabaseManager
2. Change ‘SAMPLE’ to ‘’
b. ODBC
1. Change #AbtIbmCliDatabaseManager to #AbtOdbcDatabaseManager
2. Change ‘SAMPLE’ to the name of your ODBC connection to the SAMPLE database
c. SQlite
1. Change #AbtIbmCliDatabaseManager to #AbtSQLiteDatabaseManager
 
The second snippet shows how to create the PEOPLE table for all supported databases.
The third snippet shows how to return the names of all columns in the PEOPLE table for all supported databases.
 
"Snippet #1: Execute the code to Establish a connection to the database"
(AbtDatabaseConnectionSpec forDbmClass: AbtIbmCliDatabaseManager
databaseName: 'SAMPLE') connectUsingAlias: 'SampleConSpec'
logonSpec: (AbtDatabaseLogonSpec new
id: 'userid';
password: 'password';
server: '').
"Snippet #2: Execute the code to Create a table in the current database"
| sqlDef table connection |
sqlDef := '(NAME varchar(30) NOT NULL,',
' STREET varchar(20),',
' CITY varchar(20),',
' STATE varchar(2),',
' ZIPCODE int,',
' PHONE varchar(13))'.
connection := AbtDbmSystem activeDatabaseConnectionWithAlias: 'SampleConSpec'.
table := connection createTableNamed: 'PEOPLE' definition: sqlDef.
"Snippet #3: Display the code to view column names"
| connection |
connection := AbtDbmSystem activeDatabaseConnectionWithAlias: 'SampleConSpec'.
(connection openTableNamed: 'PEOPLE')
columnNames.
Last modified date: 01/29/2015