/**
   * Method declaration
   *
   * @param ev
   */
  public void windowClosing(WindowEvent ev) {

    try {
      cConn.close();
    } catch (Exception e) {
    }

    fMain.dispose();

    if (bMustExit) {
      System.exit(0);
    }
  }
  /**
   * Method declaration
   *
   * @param c
   */
  void connect(Connection c) {

    if (c == null) {
      return;
    }

    if (cConn != null) {
      try {
        cConn.close();
      } catch (SQLException e) {
      }
    }

    cConn = c;

    try {
      dMeta = cConn.getMetaData();
      sStatement = cConn.createStatement();

      refreshTree();
    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
  /**
   * Method declaration
   *
   * @param ev
   */
  public void actionPerformed(ActionEvent ev) {

    String s = ev.getActionCommand();

    if (s == null) {
      if (ev.getSource() instanceof MenuItem) {
        MenuItem i;

        s = ((MenuItem) ev.getSource()).getLabel();
      }
    }

    if (s.equals("Execute")) {
      execute();
    } else if (s.equals("Exit")) {
      windowClosing(null);
    } else if (s.equals("Transfer")) {
      Transfer.work(null);
    } else if (s.equals("Dump")) {
      Transfer.work(new String[] {"-d"});

      /* NB - 26052002 Restore is not implemented yet in the transfer tool */
      /*
              } else if (s.equals("Restore")) {
                  Transfer.work(new String[]{"-r"});
      */
    } else if (s.equals("Logging on")) {
      jdbcSystem.setLogToSystem(true);
    } else if (s.equals("Logging off")) {
      jdbcSystem.setLogToSystem(false);
    } else if (s.equals("Refresh Tree")) {
      refreshTree();
    } else if (s.startsWith("#")) {
      int i = Integer.parseInt(s.substring(1));

      txtCommand.setText(sRecent[i]);
    } else if (s.equals("Connect...")) {
      connect(ConnectionDialog.createConnection(fMain, "Connect"));
      refreshTree();
    } else if (s.equals("Results in Grid")) {
      iResult = 0;

      pResult.removeAll();
      pResult.add("Center", gResult);
      pResult.doLayout();
    } else if (s.equals("Open Script...")) {
      FileDialog f = new FileDialog(fMain, "Open Script", FileDialog.LOAD);

      // (ulrivo): set default directory if set from command line
      if (defDirectory != null) {
        f.setDirectory(defDirectory);
      }

      f.show();

      String file = f.getFile();

      if (file != null) {
        txtCommand.setText(DatabaseManagerCommon.readFile(f.getDirectory() + file));
      }
    } else if (s.equals("Save Script...")) {
      FileDialog f = new FileDialog(fMain, "Save Script", FileDialog.SAVE);

      // (ulrivo): set default directory if set from command line
      if (defDirectory != null) {
        f.setDirectory(defDirectory);
      }

      f.show();

      String file = f.getFile();

      if (file != null) {
        DatabaseManagerCommon.writeFile(f.getDirectory() + file, txtCommand.getText());
      }
    } else if (s.equals("Save Result...")) {
      FileDialog f = new FileDialog(fMain, "Save Result", FileDialog.SAVE);

      // (ulrivo): set default directory if set from command line
      if (defDirectory != null) {
        f.setDirectory(defDirectory);
      }

      f.show();

      String file = f.getFile();

      if (file != null) {
        showResultInText();
        DatabaseManagerCommon.writeFile(f.getDirectory() + file, txtResult.getText());
      }
    } else if (s.equals("Results in Text")) {
      iResult = 1;

      pResult.removeAll();
      pResult.add("Center", txtResult);
      pResult.doLayout();
      showResultInText();
    } else if (s.equals("AutoCommit on")) {
      try {
        cConn.setAutoCommit(true);
      } catch (SQLException e) {
      }
    } else if (s.equals("AutoCommit off")) {
      try {
        cConn.setAutoCommit(false);
      } catch (SQLException e) {
      }
    } else if (s.equals("Enlarge Tree")) {
      Dimension d = tTree.getMinimumSize();

      d.width += 20;

      tTree.setMinimumSize(d);
      fMain.pack();
    } else if (s.equals("Shrink Tree")) {
      Dimension d = tTree.getMinimumSize();

      d.width -= 20;

      if (d.width >= 0) {
        tTree.setMinimumSize(d);
      }

      fMain.pack();
    } else if (s.equals("Enlarge Command")) {
      txtCommand.setRows(txtCommand.getRows() + 1);
      fMain.pack();
    } else if (s.equals("Shrink Command")) {
      int i = txtCommand.getRows() - 1;

      txtCommand.setRows(i < 1 ? 1 : i);
      fMain.pack();
    } else if (s.equals("Commit")) {
      try {
        cConn.commit();
      } catch (SQLException e) {
      }
    } else if (s.equals("Insert test data")) {
      insertTestData();
    } else if (s.equals("Rollback")) {
      try {
        cConn.rollback();
      } catch (SQLException e) {
      }
    } else if (s.equals("Disable MaxRows")) {
      try {
        sStatement.setMaxRows(0);
      } catch (SQLException e) {
      }
    } else if (s.equals("Set MaxRows to 100")) {
      try {
        sStatement.setMaxRows(100);
      } catch (SQLException e) {
      }
    } else if (s.equals("SELECT")) {
      showHelp(DatabaseManagerCommon.selectHelp);
    } else if (s.equals("INSERT")) {
      showHelp(DatabaseManagerCommon.insertHelp);
    } else if (s.equals("UPDATE")) {
      showHelp(DatabaseManagerCommon.updateHelp);
    } else if (s.equals("DELETE")) {
      showHelp(DatabaseManagerCommon.deleteHelp);
    } else if (s.equals("CREATE TABLE")) {
      showHelp(DatabaseManagerCommon.createTableHelp);
    } else if (s.equals("DROP TABLE")) {
      showHelp(DatabaseManagerCommon.dropTableHelp);
    } else if (s.equals("CREATE INDEX")) {
      showHelp(DatabaseManagerCommon.createIndexHelp);
    } else if (s.equals("DROP INDEX")) {
      showHelp(DatabaseManagerCommon.dropIndexHelp);
    } else if (s.equals("CHECKPOINT")) {
      showHelp(DatabaseManagerCommon.checkpointHelp);
    } else if (s.equals("SCRIPT")) {
      showHelp(DatabaseManagerCommon.scriptHelp);
    } else if (s.equals("SHUTDOWN")) {
      showHelp(DatabaseManagerCommon.shutdownHelp);
    } else if (s.equals("SET")) {
      showHelp(DatabaseManagerCommon.setHelp);
    } else if (s.equals("Test Script")) {
      showHelp(DatabaseManagerCommon.testHelp);
    }
  }
  /** Method declaration */
  private void refreshTree() {

    tTree.removeAll();

    try {
      int color_table = Color.yellow.getRGB();
      int color_column = Color.orange.getRGB();
      int color_index = Color.red.getRGB();

      tTree.addRow("", dMeta.getURL(), "-", 0);

      String usertables[] = {"TABLE"};
      ResultSet result = dMeta.getTables(null, null, null, usertables);
      Vector tables = new Vector();

      // sqlbob@users Added remarks.
      Vector remarks = new Vector();

      while (result.next()) {
        tables.addElement(result.getString(3));
        remarks.addElement(result.getString(5));
      }

      result.close();

      for (int i = 0; i < tables.size(); i++) {
        String name = (String) tables.elementAt(i);
        String key = "tab-" + name + "-";

        tTree.addRow(key, name, "+", color_table);

        // sqlbob@users Added remarks.
        String remark = (String) remarks.elementAt(i);

        if ((remark != null) && !remark.trim().equals("")) {
          tTree.addRow(key + "r", " " + remark);
        }

        ResultSet col = dMeta.getColumns(null, null, name, null);

        while (col.next()) {
          String c = col.getString(4);
          String k1 = key + "col-" + c + "-";

          tTree.addRow(k1, c, "+", color_column);

          String type = col.getString(6);

          tTree.addRow(k1 + "t", "Type: " + type);

          boolean nullable = col.getInt(11) != DatabaseMetaData.columnNoNulls;

          tTree.addRow(k1 + "n", "Nullable: " + nullable);
        }

        col.close();
        tTree.addRow(key + "ind", "Indices", "+", 0);

        ResultSet ind = dMeta.getIndexInfo(null, null, name, false, false);
        String oldiname = null;

        while (ind.next()) {
          boolean nonunique = ind.getBoolean(4);
          String iname = ind.getString(6);
          String k2 = key + "ind-" + iname + "-";

          if ((oldiname == null || !oldiname.equals(iname))) {
            tTree.addRow(k2, iname, "+", color_index);
            tTree.addRow(k2 + "u", "Unique: " + !nonunique);

            oldiname = iname;
          }

          String c = ind.getString(9);

          tTree.addRow(k2 + "c-" + c + "-", c);
        }

        ind.close();
      }

      tTree.addRow("p", "Properties", "+", 0);
      tTree.addRow("pu", "User: "******"pr", "ReadOnly: " + cConn.isReadOnly());
      tTree.addRow("pa", "AutoCommit: " + cConn.getAutoCommit());
      tTree.addRow("pd", "Driver: " + dMeta.getDriverName());
      tTree.addRow("pp", "Product: " + dMeta.getDatabaseProductName());
      tTree.addRow("pv", "Version: " + dMeta.getDatabaseProductVersion());
    } catch (SQLException e) {
      tTree.addRow("", "Error getting metadata:", "-", 0);
      tTree.addRow("-", e.getMessage());
      tTree.addRow("-", e.getSQLState());
    }

    tTree.update();
  }
  public void actionPerformed(ActionEvent e) {
    String a, b, c, f, g, h, j, k, l, m, n, o, p, tol = "";

    try {
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      con = DriverManager.getConnection("jdbc:odbc:db2");
      stm = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
    } catch (Exception error) {
      System.out.println(error);
    }

    if (e.getSource() == student) {
      name = "Student";
      cl.show(pnc, "cstu");
      try {
        rs = stm.executeQuery("Select * from Student");
        rs.next();
        t1.setText(rs.getString(1));
        t2.setText(rs.getString(2));
        t3.setText(rs.getString(3));
        t4.setText(rs.getString(4));
        t5.setText(rs.getString(5));
        t6.setText(rs.getString(6));
      } catch (Exception error) {
        System.out.println(error);
      }
    }

    if (e.getSource() == teacher) {
      name = "Teacher";
      cl.show(pnc, "ctea");
      try {
        rs = stm.executeQuery("Select * from Teacher");
        rs.next();
        t11.setText(rs.getString(1));
        t12.setText(rs.getString(2));
        t13.setText(rs.getString(3));
        t14.setText(rs.getString(4));
      } catch (Exception error) {
        System.out.println(error);
      }
    }

    if (e.getSource() == course) {
      name = "Course";
      cl.show(pnc, "ccou");
      try {
        rs = stm.executeQuery("Select * from Course");
        rs.next();
        t7.setText(rs.getString(1));
        t8.setText(rs.getString(2));
        t9.setText(rs.getString(3));
        t0.setText(rs.getString(4));
      } catch (Exception error) {
        System.out.println(error);
      }
    }

    if (e.getSource() == result) {
      name = "Result";
      cl.show(pnc, "cres");
      try {
        rs = stm.executeQuery("Select * from Result");
        rs.next();
        t15.setText(rs.getString(1));
        t16.setText(rs.getString(2));
        t17.setText(rs.getString(3));
        t18.setText(rs.getString(4));
        t19.setText(rs.getString(5));
        t20.setText(rs.getString(6));
        t21.setText(rs.getString(7));
        t22.setText(rs.getString(8));
        t23.setText(rs.getString(9));
        t24.setText(rs.getString(10));
        t25.setText(rs.getString(11));
        t26.setText(rs.getString(12));
        t27.setText(rs.getString(13));
      } catch (Exception error) {
        System.out.println(error);
      }
    }

    if (e.getSource() == b6) {
      Vector cols = new Vector();
      Vector rows = new Vector();

      if (z == 1) {
        String sql = "Select * from " + co;
        try {
          rs = stm.executeQuery(sql);
          meta = rs.getMetaData();
          for (int i = 1; i <= meta.getColumnCount(); i++) cols.addElement(meta.getColumnName(i));
          while (rs.next()) {
            Vector currow = new Vector();
            for (int i = 1; i <= meta.getColumnCount(); i++) currow.addElement(rs.getString(i));
            rows.addElement(currow);
          }
        } catch (Exception ex) {
          System.out.print(ex);
        }
        tb = new JTable(rows, cols);
        js = new JScrollPane(tb);
        pne2.remove(js);
        pne2.add(blk, "bb");
        cl2.show(pne2, "bb");
        pne2.add(js, "jjs");
        cl2.show(pne2, "jjs");
        pne2.remove(blk);
        z = 0;
      }
    }

    if (e.getSource() == b1) // **** ADD BUTTON ****//
    {
      if (name == "Student") {
        a = t1.getText();
        b = t2.getText();
        c = t3.getText();
        f = t4.getText();
        g = t5.getText();
        h = t6.getText();

        tol =
            "Insert into Student values ('"
                + a
                + "','"
                + b
                + "','"
                + c
                + "','"
                + f
                + "','"
                + g
                + "','"
                + h
                + "')";
      }

      if (name == "Teacher") {
        a = t11.getText();
        b = t12.getText();
        c = t13.getText();
        f = t14.getText();

        tol = "Insert into Teacher values ('" + a + "','" + b + "','" + c + "','" + f + "')";
      }

      if (name == "Course") {
        a = t7.getText();
        b = t8.getText();
        c = t9.getText();
        f = t0.getText();

        tol = "Insert into Course values ('" + a + "','" + b + "','" + c + "','" + f + "')";
      }

      if (name == "Result") {
        a = t15.getText();
        b = t16.getText();
        c = t17.getText();
        f = t18.getText();
        g = t19.getText();
        h = t20.getText();
        j = t21.getText();
        k = t22.getText();
        l = t23.getText();
        m = t24.getText();
        n = t25.getText();
        o = t26.getText();
        p = t27.getText();

        tol =
            "Insert into Result values ('"
                + a
                + "','"
                + b
                + "','"
                + c
                + "','"
                + f
                + "','"
                + g
                + "','"
                + h
                + "','"
                + j
                + "','"
                + k
                + "','"
                + l
                + "','"
                + m
                + "','"
                + n
                + "','"
                + o
                + "','"
                + p
                + "')";
      }
      try {
        stm.executeUpdate(tol);
      } catch (Exception error) {
        System.out.println(error);
      }
    }

    if (e.getSource() == b2) // **** DELETE BUTTON ****//
    {
      if (name == "Student") {
        b = t2.getText();
        tol = "Delete from Student where Id = '" + b + "'";
      }

      if (name == "Teacher") {
        b = t12.getText();
        tol = "Delete from Teacher where Id = '" + b + "'";
      }

      if (name == "Course") {
        b = t8.getText();
        tol = "Delete from Course where Id = '" + b + "'";
      }

      if (name == "Result") {
        b = t16.getText();
        tol = "Delete from Result where Code = '" + b + "'";
      }
      try {
        stm.executeUpdate(tol);
      } catch (Exception error) {
        System.out.println(error);
      }
    }

    if (e.getSource() == b3) // **** UPDATE BUTTON ****//
    {
      if (name == "Student") {
        a = t1.getText();
        b = t2.getText();
        c = t3.getText();
        f = t4.getText();
        g = t5.getText();
        h = t6.getText();

        tol =
            "Update Student set Name = '"
                + a
                + "', ID = '"
                + b
                + "', Dept = '"
                + c
                + "', CGPA = '"
                + f
                + "', Address = '"
                + g
                + "', Cell = '"
                + h
                + "' where ID = '"
                + b
                + "'";
      }

      if (name == "Teacher") {
        a = t11.getText();
        b = t12.getText();
        c = t13.getText();
        f = t14.getText();

        tol =
            "Update Teacher set Name = '"
                + a
                + "', ID = '"
                + b
                + "', Dept = '"
                + c
                + "', Course = '"
                + f
                + "' where ID = '"
                + b
                + "'";
      }

      if (name == "Course") {
        a = t7.getText();
        b = t8.getText();
        c = t9.getText();
        f = t0.getText();

        tol =
            "Update Course set Name = '"
                + a
                + "', Code = '"
                + b
                + "', Credit = '"
                + c
                + "', Prerecusite = '"
                + f
                + "' where Code = '"
                + b
                + "'";
      }

      if (name == "Result") {
        a = t15.getText();
        b = t16.getText();
        c = t17.getText();
        f = t18.getText();
        g = t19.getText();
        h = t20.getText();
        j = t21.getText();
        k = t22.getText();
        l = t23.getText();
        m = t24.getText();
        n = t25.getText();
        o = t26.getText();
        p = t27.getText();

        tol =
            "Update Result set Course = '"
                + a
                + "', Code = '"
                + b
                + "', Credit = '"
                + c
                + "', A = '"
                + f
                + "', B+ = '"
                + g
                + "', B = '"
                + h
                + "', C+ = '"
                + j
                + "', C = '"
                + k
                + "', D+ = '"
                + l
                + "', D = '"
                + m
                + "', F = '"
                + n
                + "', I = '"
                + o
                + "', W = '"
                + p
                + "' where Code = '"
                + b
                + "'";
        // JOptionPane.showMessageDialog(null,tol,null,JOptionPane.PLAIN_MESSAGE);
        // tol = "Update Result set Course = '"+a+"', Code = '"+b+"', Credit = '"+c+"' where Code =
        // '"+b+"'";
      }
      try {
        stm.executeUpdate(tol);
      } catch (Exception error) {
        System.out.println(error);
      }
    }

    if (e.getSource() == b4) // **** NEXT BUTTON ****//
    {
      if (name == "Student") {
        try {
          if (rs.next()) {
            t1.setText(rs.getString(1));
            t2.setText(rs.getString(2));
            t3.setText(rs.getString(3));
            t4.setText(rs.getString(4));
            t5.setText(rs.getString(5));
            t6.setText(rs.getString(6));
          }
        } catch (Exception error) {
          System.out.println(error);
        }
      }

      if (name == "Teacher") {
        try {
          if (rs.next()) {
            t11.setText(rs.getString(1));
            t12.setText(rs.getString(2));
            t13.setText(rs.getString(3));
            t14.setText(rs.getString(4));
          }
        } catch (Exception error) {
          System.out.println(error);
        }
      }

      if (name == "Course") {
        try {
          if (rs.next()) {
            t7.setText(rs.getString(1));
            t8.setText(rs.getString(2));
            t9.setText(rs.getString(3));
            t0.setText(rs.getString(4));
          }
        } catch (Exception error) {
          System.out.println(error);
        }
      }

      if (name == "Result") {
        try {
          if (rs.next()) {
            t15.setText(rs.getString(1));
            t16.setText(rs.getString(2));
            t17.setText(rs.getString(3));
            t18.setText(rs.getString(4));
            t19.setText(rs.getString(5));
            t20.setText(rs.getString(6));
            t21.setText(rs.getString(7));
            t22.setText(rs.getString(8));
            t23.setText(rs.getString(9));
            t24.setText(rs.getString(10));
            t25.setText(rs.getString(11));
            t26.setText(rs.getString(12));
            t27.setText(rs.getString(13));
          }
        } catch (Exception error) {
          System.out.println(error);
        }
      }
    }

    if (e.getSource() == b5) // **** PREVIOUS BUTTON ****//
    {
      if (name == "Student") {
        try {
          if (rs.previous()) {
            t1.setText(rs.getString(1));
            t2.setText(rs.getString(2));
            t3.setText(rs.getString(3));
            t4.setText(rs.getString(4));
            t5.setText(rs.getString(5));
            t6.setText(rs.getString(6));
          }
        } catch (Exception error) {
          System.out.println(error);
        }
      }

      if (name == "Teacher") {
        try {
          if (rs.previous()) {
            t11.setText(rs.getString(1));
            t12.setText(rs.getString(2));
            t13.setText(rs.getString(3));
            t14.setText(rs.getString(4));
          }
        } catch (Exception error) {
          System.out.println(error);
        }
      }

      if (name == "Course") {
        try {
          if (rs.previous()) {
            t7.setText(rs.getString(1));
            t8.setText(rs.getString(2));
            t9.setText(rs.getString(3));
            t0.setText(rs.getString(4));
          }
        } catch (Exception error) {
          System.out.println(error);
        }
      }

      if (name == "Result") {
        try {
          if (rs.previous()) {
            t15.setText(rs.getString(1));
            t16.setText(rs.getString(2));
            t17.setText(rs.getString(3));
            t18.setText(rs.getString(4));
            t19.setText(rs.getString(5));
            t20.setText(rs.getString(6));
            t21.setText(rs.getString(7));
            t22.setText(rs.getString(8));
            t23.setText(rs.getString(9));
            t24.setText(rs.getString(10));
            t25.setText(rs.getString(11));
            t26.setText(rs.getString(12));
            t27.setText(rs.getString(13));
          }
        } catch (Exception error) {
          System.out.println(error);
        }
      }
    }
  }
  public void actionPerformed(ActionEvent ae) {
    os = a.getText();
    Pattern pat = Pattern.compile("[ .]");
    String ms[] = pat.split(os), v; // Get whole String from Text area in tokens form

    Pattern pat1 = Pattern.compile("[ ]");
    String ms1[] = pat1.split(os); // for string aaray

    int hcode[] = {100, 102, 220, 110, 111},
        ecode[] = new int[20],
        j,
        p = 0; // p for check entry & hcode=Hindi lang.code  ecode=English lang. code
    ResultSet rs;
    b.setText("");
    try {
      Class.forName("oracle.jdbc.driver.OracleDriver");
      Connection con =
          DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "student");
      Statement stmt = con.createStatement();
      for (i = 0; i <= ms.length; i++) {
        v = "'" + ms[i] + "'";
        p = 0;
        if (p == 0) {
          rs = stmt.executeQuery("select hnoun from noun where enoun=" + v);
          while (rs.next()) {
            ms1[i] = (rs.getString(1));
            p++;
            ecode[i] = 100;
          }
        }

        if (p == 0) {
          rs = stmt.executeQuery("select hhv from hv where ehv=" + v);
          while (rs.next()) {
            ms1[i] = (rs.getString(1));
            p++;
            ecode[i] = 111;
          }
        }

        if (p == 0) {
          rs = stmt.executeQuery("select hneg from neg where eneg=" + v);
          while (rs.next()) {
            ms1[i] = (rs.getString(1));
            p++;
            ecode[i] = 220;
          }
        }

        if (p == 0) {
          rs = stmt.executeQuery("select hverb from verb where everb=" + v);
          while (rs.next()) {
            ms1[i] = (rs.getString(1));
            p++;
            ecode[i] = 110;
          }
        }

        if (p == 0) {
          rs = stmt.executeQuery("select hpre from pre where epre=" + v);
          while (rs.next()) {
            ms1[i] = (rs.getString(1));
            p++;
            ecode[i] = 140;
          }
        }
        if (p == 0) {
          rs = stmt.executeQuery("select hpro from pro where epro=" + v);
          while (rs.next()) {
            ms1[i] = (rs.getString(1));
            p++;
            ecode[i] = 102;
          }
        }

        if (p == 0) {
          rs = stmt.executeQuery("select hart from art where eart=" + v);
          while (rs.next()) {
            ms1[i] = (rs.getString(1));
            p++;
            ecode[i] = 123;
          }
        }
      }

      con.close();

    } catch (Exception e) {
      System.out.println(e);
    }

    for (i = 0; i < 5; i++) {
      for (j = 0; j < ms.length; j++) {
        if (hcode[i] == ecode[j]) {
          b.append(ms1[j] + " "); // print to hindi code wise
        }
      }
    }
  }