JDBCStoreSchemaGenerator code example

The JDBCStoreSchemaGenerator is normally used by a database administration application, which will create and modify the STORE table needed by the applications using the store. The database administration application calls the JDBCStoreSchemaGenerator class, which provides the methods to perform this kind of administrative task. The JDBCStoreSchemaGenerator can therefore be considered independent from the application that is requesting the store services. The application must take care, before requesting the database connection, to register and load the specific JDBC driver needed to work with the database.

The following lines are column definitions for a sample database administration application.

ACCOUNT_NUMBER CHAR(14)

AMOUNT INTEGER

DESCRIPTION VARCHAR(50)

THE_DATE DATE

The following is the code for the runnable class StoreTableManagement, which builds a table using these column definitions:
import java.util.Enumeration; 
import java.sql.*;
import com.ibm.btt.base.*;
import com.ibm.btt.services.jdbc.*;

public class StoreTableManagement {
/**
* This class creates a store table that will later on be used by the
applications requesting the store services
*/

public static void main(String args[]) throws java.io.IOException,
DSEObjectNotFoundException {
    JDBCStoreSchemaGenerator ssg =null;

    // 1) Instantiate JDBCStorechemaGenerator...

    ssg = new JDBCStoreSchemaGenerator();

    // 2) Connect to Database...
    try {
        ssg.loadDriver("COM.ibm.db2.jdbc.net.DB2Driver");
        ssg.connect("jdbc:db2://myhs:8888/mydb","MYUSER","MYPASS");
    } catch (Exception e ) {
        e.printStackTrace();
    return;
    }

    // 3) Create the store table
    String tableDefinition = "ACCOUNT_NUMBER CHAR(14), AMOUNTINTEGER, 
                DESCRIPTION VARCHAR(50), THE_DATE DATE";
    String tableName = "StoreTable";
    try {
        // Generating Database Table...
        ssg.generateTable(tableName, tableDefinition);>
        // Close the database connection
        ssg.disconnect();
    } // End try
    catch (Exception e ) {
        e.printStackTrace();
    }
}