コード例 #1
0
 /** Gets a title for the data presented in the tree node. */
 public String getTitle() {
   try {
     Connection con = conProv.getConnection();
     DatabaseMetaData dmd = con.getMetaData();
     StringBuffer sb = new StringBuffer();
     sb.append(dmd.getDatabaseProductName());
     sb.append(" - ");
     dmd = con.getMetaData();
     sb.append(conProv.getServerName());
     return sb.toString();
   } catch (Exception e) {
     return "[Not Connected]";
   }
 }
コード例 #2
0
  /**
   * Refreshes the tree view with data from the server.
   *
   * @exception ClassNotFoundException indicates there was an error connecting to the database.
   * @exception IllegalAccessException indicates there was an error connecting to the database.
   * @exception InstantiationException indicates there was an error connecting to the database.
   * @exception SQLException indicates that an error occurred while querying the database server.
   */
  public void refresh()
      throws ClassNotFoundException, IllegalAccessException, InstantiationException, SQLException {
    notifyStatusListeners(
        new StatusEvent(this, StatusTypeEnum.BUSY, "Loading the list of catalogs."));
    try {
      // Clear children
      if (children != null && children.size() > 0) {
        int indices[] = new int[children.size()];
        Object nodes[] = new Object[children.size()];
        for (int i = 0; i < indices.length; i++) {
          indices[i] = i;
          nodes[i] = children.elementAt(i);
        }
        notifyParent(NODES_REMOVED, new Stack(), indices, nodes);
        children = new Vector();
      }

      Connection con = conProv.getConnection();

      // Get a list of all catalogs unless we are connected to
      // Postgresql.
      // <<HACK>>Postgresql lists all available catalogs, but
      // returns metadata for only the currently connected catalog.
      // Therefore, showing all catalogs has only a little value.
      if (!(conProv instanceof us.pcsw.dbbrowser.cp.postgresql.ConnectionProvider)) {
        DatabaseMetaData dmd = con.getMetaData();
        ResultSet rs = dmd.getCatalogs();
        while (rs.next()) {
          insertChildNode(new CatalogTreeNode(this, con, rs.getString("TABLE_CAT")));
        }
        rs.close();
      }
      if (children == null || children.size() == 0) {
        // Some RDBMSs do not have a concept of catalogs
        insertChildNode(new CatalogTreeNode(this, con, null));
      }
    } catch (Throwable t) {
      notifyStatusListeners(new StatusEvent(this, t));
    } finally {
      notifyStatusListeners(
          new StatusEvent(this, StatusTypeEnum.NOT_BUSY, "Finished loading the list of catalogs."));
    }
  }
コード例 #3
0
 public String toString() {
   return conProv.getServerName();
 }