001package ca.bc.webarts.tools;
002import java.sql.*;
003public class DBTables {
004
005 /**
006  *
007  */
008    static private String db2ServerName = "Aurora1";
009 /**
010  *
011  */
012    static private String db2ServerPort = "6790";
013 /**
014  *
015  */
016   static private String db2DBName = "sample";
017 /**
018  *
019  */
020   static private String db2UserId = "tgutwin";
021 /**
022  *
023  */
024   static private String db2UserPassword = "GetYourOwn";
025 /**
026  *
027  */
028    static String adminEmail = "webadmin@webarts.bc.ca";
029 /**
030  *
031  */
032    static String adminEmailURL = "<A HREF=\"" +adminEmail+"\">"+adminEmail+"</A>";
033 /**
034  *
035  */
036    static String jdbcDriverName = "COM.ibm.db2.jdbc.app.DB2Driver";
037 /**
038  *
039  */
040    static String jdbcDriverErrorMsg = "Sorry, a JDBC Driver ERROR occurred.  I won't be able to process you request";
041 /**
042  *
043  */
044    static String sqlDriverErrorMsg = "Sorry, a SQL ERROR occurred.  I won't be able to process you request";
045 /**
046  *
047  */
048        static String reportErrorMsg = "Please copy the follwing information and email it to "+adminEmail;
049
050         private boolean atEOF;
051         private short numColumns =0;
052         private String tableNm;
053         private String[][] tableColumns;
054
055 /**
056  *
057  */
058        static Class driver;
059 /**
060  *
061  */
062   static Connection con = null;
063
064  static {
065      try {
066         //  register the driver with DriverManager
067         //  The newInstance() call is needed for the sample to work with
068         //  JDK 1.1.1 on OS/2, where the Class.forName() method does not
069         //  run the static initializer. For other JDKs, the newInstance
070         //  call can be omitted.
071
072         driver = (Class) Class.forName(jdbcDriverName).newInstance();
073         System.out.println("We Registered The Driver!");
074      }
075      catch (Exception e) {
076              System.out.println(jdbcDriverErrorMsg);
077              System.out.println(e);
078              System.out.println(reportErrorMsg);
079        e.printStackTrace();
080      }
081   }
082
083/**
084  *
085  */
086   private String getNextTableName(){
087           String retVal = "";
088
089           return retVal;
090   }
091/**
092  *
093  */
094  private short getNextTable(){
095        short retVal = 0;
096
097        return retVal;
098   }
099/**
100 * This method gets called if this applet is envoked as an application.
101 */
102public  void main(String argv[]){
103
104        /* get the commandline parms */
105         switch (argv.length) {
106                 case 0:
107                         db2DBName = "sample";
108                         break;
109
110                 case 1:  /* database name */
111                         db2DBName = argv[0];
112                         break;
113
114                 default:
115                         /* get the command switches */
116
117                         db2DBName = argv[argv.length -1];
118                 }
119
120       try {
121         //  construct the URL ( sample is the database name )
122         String url = "jdbc:db2:"+ db2DBName;
123
124         //  connect to database with userid and password
125         con = DriverManager.getConnection(url, db2UserId, db2UserPassword );
126
127
128          while (!atEOF){
129                  /* read the input file to get the next Itablename and columns */
130                  tableNm = getNextTableName();
131                  numColumns = getNextTable();
132                  if(tableNm.length() >0 && numColumns >0){
133                          tableColumns = new String[numColumns][3];
134                     createTable(tableNm, tableColumns, numColumns);
135                  }
136                  else {
137                        System.err.println("fileErrorMsg");
138                        System.err.println(reportErrorMsg);
139                        System.err.println("e.printStackTrace()");
140                  }
141          }
142         con.close();
143        } catch( Exception e ) {
144              System.err.println(jdbcDriverErrorMsg);
145              System.err.println(reportErrorMsg);
146              System.err.println("e.printStackTrace()");
147              System.exit(1);
148        }
149   }
150
151  private void createTable(String tableNm, String[][] tableColumns, short numColumns)
152  {
153  }
154
155}