JDBCJournalSchemaGenerator code example

The JDBCJournalSchemaGenerator is normally used by a database administration application that will create and modify the tables needed by the applications using the journal. It can, then, be considered independent from the application that is requesting the journal services. Before requesting the database connection, the application must register and load the specific JDBC driver needed to work with the database, according to the database environment, as explained in Accessing a relational database using the JDBC interface in the Database Services documentation. The application can then request a connection to the database using the following method:
JDBCJournalSchemaGenerator jsg=new JDBCJournalSchemaGenerator();
jsg.connect(aDatabaseURL, aUser, aPassword

Details about the syntax of the argument aDatabaseURL can be found in the specific JDBC Driver documentation or in JDBC URLs in the Database Services documentation.

The aUser and aPassword arguments are the userid and password to log on to the database.

The following is a sample of what this database administration application can do. The application is a runable JournalSchemaManagement class that creates the journal tables for two entities, UserA and UserB, with three generations and three table columns: BRANCHNUMBER CHAR(4), AGREEMENTNUMBER INTEGER, and DUEDATE DATE.

This sample and the following database access samples are working with a remote DB2® server listening on TCP/IP port 8888. Because the sample application will work with a remote database, the application will have to register and load the specific JDBC driver before connecting to the database. This sample shows the JDBC DB2 Net Driver, which will enable the application to work with a DBMS installed on a remote workstation.

import java.util.Enumeration;
import java.sql.*;
import com.ibm.btt.base.*;
import com.ibm.btt.services.jdbc.*;
import com.ibm.btt.services.jdbc.journal.*;

public class JournalSchemaManagement { 

public static Connection connection = null;
public static JDBCJournalSchemaGenerator jsg = null;

/**
* This method creates the journal tables using the JDBCJournalSchemaGenerator class
*/
public static void main(String args[]) { 

try { 

  // 1) Load the JDBC DB2 driver 
jsg = new JDBCJournalSchemaGenerator();
	jsg.loadDriver(dbdriver);

  // 2) Instantiate JDBCJournalSchemaGenerator...
  System.out.println(">>> Instantiating JDBCJournalGenerator...");
jsg.connect(dburl, dbuser, dbpasswd);

  // 3) Generate all Tables...
String myJournalSchemaName="mySchema";
Vector entities = new Vector();
entities.addElement( new String ("UserA"));
entities.addElement( new String ("UserB"));
String tableDefinition = "BRANCHNUMBER CHAR(4), AGREEMENTNUMBER INTEGER, DUEDATE
DATE";
try { 
  System.out.println(">>> Generating Database Schema...");
  jsg.generateSchema(entities, 3, tableDefinition, myJournalSchemaName);
  System.out.println(">>> Disconnecting from the database...");
  jsg.disconnect();				
} catch (DSEInvalidArgumentException e) { 
  System.out.println(e.getMessage());
  return;
} catch (DSEInvalidRequestException e) { 
  System.out.println(e.getMessage());
} catch (DSESQLException e) { 
  System.out.println(e.getMessage());
  return;
} catch (DSEInternalErrorException e) { 
  System.out.println(e.getMessage());
  return;
}
}