Creating the STORE table

About this task

After the connection to the database has been established, the application then generates the table in the database, using one of the following methods:
void generateTable(String aTableName, String storeTableDefinition) 
or
void generateTable(String aSchemaName, String aTableName, String storeTableDefinition

The first argument is the table name, and the second argument is a string with the SQL definition of the STORE table. You can also give an additional argument, the name of the schema where the table is to be created. If the schema does not have to be explicitly created in the database, the application must set the createSchema attribute to false before calling the generateTable() method.

Note that the STORE table SQL definition does not need to include the record identification DSERECID primary key column and the record mark DSERECMK column. The table generator automatically adds these columns to the table definition.

The following sample code shows the use of the generateTable method:
ssg = new JDBCStoreSchemaGenerator();
String tableDefinition = "ACCOUNT_NUMBER CHAR(14), 
    AMOUNT INTEGER, OPERATION_ID VARCHAR(2)";
ssg.generateTable("storeTable",tableDefinition);

When using DB2® UDB for OS/390®, the database name where the STORE table is created must be specified, as the database URL refers to a location where different databases can be defined. You can do this using the setDatabaseName method. If the databaseName attribute is not null and not blank, the JDBCStoreSchemaGenerator creates the table in the database specified by the databaseName attribute value within the location set in the database URL specification.

The following table describes the JDBCStoreSchemaGenerator arguments, their default values, and when they should be set to a different value:
Table 1. JDBCStoreSchemaGenerator arguments
Attribute name Description
schemaName Contains the name of the store schema. If you do not set this attribute, either explicitly or as an argument of the generateSchema() method, the method uses the default value of null. When the schema name is null, the DBMS uses only the table name to create the table in the default schema assigned to the user executing the CREATE TABLE statement. If you set the name of the schema, the schema must already exist as result of the creation of a user in the database system. In this case, the schema name always matches the name of a defined user.

When the DBMS is Oracle, the application may need to create the STORE table in the user's default schema. If this is the case, use the default value of null.

Default value: null
createSchema Indicates whether the schema identified by schemaName must be explicitly created before the tables are created in it. If this attribute is set to false, the schema identified by schemaName must already be available in the database.

When the DBMS is Oracle and a schemaName has been set, set this attribute to false as the schemas are automatically created when a new database user is defined and no other schemas can be created.

When the DBMS is DB2 UDB for OS/390, set this attribute to false.

Default value: true
createIndex Indicates whether the STORE table index must be explicitly created after creating the table. DB2 for NT /AIX and Oracle automatically create indexes on the table primary keys when the table is created. DB2 for OS/390 requires an explicit creation of the indexes after it creates the tables, so you must set this attribute to true for this environment.

Default value: false
databaseName Keeps the database name when working with DB2 UDB in OS/390. In this environment the database URL as set in the database connection has the following format: jdbc:db2os390:<location>. The <location> is the name of a shared database subsystem with different databases and storage groups defined in it. The databaseName attribute indicates which database contains the table. If you do not specify a value, the DBMS creates the STORE table in the default database within this location.

See the JDBCStoreSchemaGenerator code example.