Previous Topic

Next Topic

Define

The Define() step is where specific data definitions are established by your application and/or process. This involves defining columns/fields and creating the tables/files with optional indices.

Below is the code for Define():

   //
   // Define()
   //
   // Create the tables
   //
   private static void Define ()
   {
      System.out.println("DEFINE");

      Create_CustomerMaster_Table();
      Create_CustomerOrders_Table();
      Create_OrderItems_Table();
      Create_ItemMaster_Table();
   }


   //
   // Create_CustomerMaster_Table()
   //
   // Create the table CustomerMaster
   //
   private static void Create_CustomerMaster_Table ()
   {
      // define table CustomerMaster
      System.out.println("\ttable CustomerMaster");

      try
      {
         stmt.executeUpdate("CREATE TABLE custmast (" +
            "cm_custnumb CHAR(4), " +
            "cm_custzipc CHAR(9), " +
            "cm_custstat CHAR(2), " +
            "cm_custrtng CHAR(1), " +
            "cm_custname VARCHAR(47), " +
            "cm_custaddr VARCHAR(47), " +
            "cm_custcity VARCHAR(47))"
         );
      }
      catch (SQLException e)
      {
         Handle_Exception(e);
      }

      try
      {
         stmt.executeUpdate("CREATE UNIQUE INDEX cm_custnumb_idx ON custmast (cm_custnumb)");
      }
      catch (SQLException e)
      {
         Handle_Exception(e);
      }
   }


   //
   // Create_CustomerOrders_Table()
   //
   // Create the table CustomerOrders
   //
   private static void Create_CustomerOrders_Table ()
   {
      // define table CustomerOrders
      System.out.println("\ttable CustomerOrders");

      try
      {
         stmt.executeUpdate("CREATE TABLE custordr (" +
            "co_ordrdate DATE, " +
            "co_promdate DATE, " +
            "co_ordrnumb CHAR(6), " +
            "co_custnumb CHAR(4))"
         );
      }
      catch (SQLException e)
      {
         Handle_Exception(e);
      }

      try
      {
         stmt.executeUpdate("CREATE UNIQUE INDEX co_ordrnumb_idx ON custordr (co_ordrnumb)");
         stmt.executeUpdate("CREATE INDEX co_custnumb_idx ON custordr (co_custnumb)");
      }
      catch (SQLException e)
      {
         Handle_Exception(e);
      }
   }


   //
   // Create_OrderItems_Table()
   //
   // Create the table OrderItems
   //
   private static void Create_OrderItems_Table ()
   {
      // define table OrderItems
      System.out.println("\ttable OrderItems");

      try
      {
         stmt.executeUpdate("CREATE TABLE ordritem (" +
            "oi_sequnumb SMALLINT, " +
            "oi_quantity SMALLINT, " +
            "oi_ordrnumb CHAR(6), " +
            "oi_itemnumb CHAR(5))"
         );
      }
      catch (SQLException e)
      {
         Handle_Exception(e);
      }

      try
      {
         stmt.executeUpdate("CREATE UNIQUE INDEX oi_ordrnumb_idx ON ordritem (oi_ordrnumb, oi_sequnumb)");
         stmt.executeUpdate("CREATE INDEX oi_itemnumb_idx ON ordritem (oi_itemnumb)");
      }
      catch (SQLException e)
      {
         Handle_Exception(e);
      }
   }


   //
   // Create_ItemMaster_Table()
   //
   // Create the table ItemMaster
   //
   private static void Create_ItemMaster_Table ()
   {
      // define table ItemMaster
      System.out.println("\ttable ItemMaster");

      try
      {
         stmt.executeUpdate("CREATE TABLE itemmast (" +
            "im_itemwght INTEGER, " +
            "im_itempric MONEY, " +
            "im_itemnumb CHAR(5), " +
            "im_itemdesc VARCHAR(47))"
         );
      }
      catch (SQLException e)
      {
         Handle_Exception(e);
      }

      try
      {
         stmt.executeUpdate("CREATE UNIQUE INDEX im_itemnumb_idx ON itemmast (im_itemnumb)");
      }
      catch (SQLException e)
      {
         Handle_Exception(e);
      }
   }