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.*; 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) Instantiate JDBCJournalSchemaGenerator... System.out.println(">>> Instantiating JDBCJournalGenerator..."); jsg = new JDBCJournalSchemaGenerator(); // 2) Load the JDBC DB2 driver jsg.loadDriver("COM.ibm.db2.jdbc.net.DB2Driver"); // 3) Request a database connection jsg.connect("jdbc:db2://myhsn:8888/myDbn", "MYUSER", "MYPASS"); } catch (DSEException e ) {System.out.println(e.getMessage()); return; } // 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; } }