/**
   * Method declaration
   *
   * @param r
   */
  void formatResultSet(ResultSet r) {

    if (r == null) {
      String g[] = new String[1];

      g[0] = "Result";

      gResult.setHead(g);

      g[0] = "(empty)";

      gResult.addRow(g);

      return;
    }

    try {
      ResultSetMetaData m = r.getMetaData();
      int col = m.getColumnCount();
      String h[] = new String[col];

      for (int i = 1; i <= col; i++) {
        h[i - 1] = m.getColumnLabel(i);
      }

      gResult.setHead(h);

      while (r.next()) {
        for (int i = 1; i <= col; i++) {
          h[i - 1] = r.getString(i);

          if (r.wasNull()) {
            h[i - 1] = "(null)";
          }
        }

        gResult.addRow(h);
      }

      r.close();
    } catch (SQLException e) {
    }
  }
  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);
        }
      }
    }
  }
  /** 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 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
        }
      }
    }
  }