⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 metadatavalues.java

📁 eq跨平台查询工具源码 eq跨平台查询工具源码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        }        finally {            releaseResources(rs);        }             }        /** <p>Retrieves the column names for the specified     *  database table and schema as a <code>Vector</code>     *  object.     *     *  @param the database table name     *  @param the database schema name     *  @return the column names <code>Vector</code>     */    public Vector<String> getColumnNamesVector(String table, String schema)         throws DataSourceException {        ResultSet rs = null;        try {            ensureConnection();                        if (schema == null) {                schema = getSchemaName().toUpperCase();            }                        DatabaseMetaData dmd = connection.getMetaData();            rs = dmd.getColumns(null, schema, table, null);                        Vector<String> v = new Vector<String>();                        while (rs.next()) {                v.add(rs.getString(4).toUpperCase());            }            return v;                    }         catch (SQLException e) {            throw new DataSourceException(e);        }                finally {            releaseResources(rs);        }             }        /** <p>Retrieves the specified schema's     *  database table names within a <code>Vector</code>.     *     *  @return the table names     */    public Vector<String> getSchemaTables(String schema) throws DataSourceException {        ResultSet rs = null;        try {            ensureConnection();                        String _schema = null;            boolean valueFound = false;                        DatabaseMetaData dmd = connection.getMetaData();            rs = dmd.getSchemas();                        while (rs.next()) {                _schema = rs.getString(1);                                if (_schema.equalsIgnoreCase(schema)) {                    valueFound = true;                    break;                }                             }                         rs.close();                        if (!valueFound) {                _schema = schema;            }                        String[] type = {"TABLE"};            rs = dmd.getTables(null, _schema, null, type);                        Vector<String> v = new Vector<String>();                        while (rs.next()) {                v.add(rs.getString(3));            }                        rs.close();                        return v;        }                 catch (SQLException e) {            throw new DataSourceException(e);        }        finally {            releaseResources(rs);        }             }        public Vector<ColumnData> getColumnMetaDataVector(                    String name, String schema, String catalog)                     throws DataSourceException {        ResultSet rs = null;        try {                        ensureConnection();                        if (schema == null) {                schema = getSchemaName().toUpperCase();            }                        DatabaseMetaData dmd = connection.getMetaData();            rs = dmd.getColumns(catalog, schema, name, null);                        Vector v = new Vector();            String columnName = null;                        while (rs.next()) {                ColumnData cd = new ColumnData();                cd.setColumnName(rs.getString(4));                cd.setSQLType(rs.getInt(5));                cd.setColumnType(rs.getString(6));                cd.setColumnSize(rs.getInt(7));                cd.setColumnRequired(rs.getInt(11));                cd.setTableName(name);                v.add(cd);            }                         return v;        }         catch (SQLException e) {            throw new DataSourceException(e);        }        finally {            releaseResources(rs);        }             }    /** <p>Retrieves the complete column meta data     *  for the specified database table and schema.     *  <p>Each column and associated data is stored within     *  <code>ColumnData</code> objects and added to the     *  <code>Vector</code> object to be returned.     *     *  @param the database table name     *  @param the database schema name     *  @return the table column meta data     */    public Vector<ColumnData> getColumnMetaDataVector(String name, String schema)         throws DataSourceException {        return getColumnMetaDataVector(name, schema, null);    }        public DatabaseObject[] getTables(String catalog,                                       String schema,                                       String[] types)        throws DataSourceException {        ResultSet rs = null;        try {            ensureConnection();            DatabaseMetaData dmd = connection.getMetaData();            rs = dmd.getTables(catalog, schema, null, types);                        if (rs == null) {                return new DatabaseObject[0];            }                        ArrayList list = new ArrayList();            while (rs.next()) {                DatabaseObject object = new DatabaseObject();                object.setCatalogName(rs.getString(1));                object.setSchemaName(rs.getString(2));                object.setName(rs.getString(3));                object.setMetaDataKey(rs.getString(4));                object.setRemarks(rs.getString(5));                list.add(object);            }                         return (DatabaseObject[])list.toArray(                                     new DatabaseObject[list.size()]);                    }         catch (SQLException e) {            throw new DataSourceException(e);        }        finally {            releaseResources(rs);        }     }        public static final int STRING_FUNCTIONS = 0;        public static final int TIME_DATE_FUNCTIONS = 1;        public static final int NUMERIC_FUNCTIONS = 2;        public String[] getSystemFunctions(int type) throws DataSourceException {        try {            ensureConnection();            DatabaseMetaData dmd = connection.getMetaData();            String functions = null;            switch (type) {                case STRING_FUNCTIONS:                    functions = dmd.getStringFunctions();                    break;                case TIME_DATE_FUNCTIONS:                    functions = dmd.getTimeDateFunctions();                    break;                case NUMERIC_FUNCTIONS:                    functions = dmd.getNumericFunctions();                    break;            }            if (!MiscUtils.isNull(functions)) {                StringTokenizer st = new StringTokenizer(functions, ",");                List<String> list = new ArrayList<String>(st.countTokens());                while (st.hasMoreTokens()) {                    list.add(st.nextToken());                }                return (String[])list.toArray(new String[list.size()]);            }            return new String[0];        }        catch (SQLException e) {            throw new DataSourceException(e);        }    }        /**     * Returns the procedure term used in the current connected      * database.     *     * @return the procedure term     */    public String getProcedureTerm() throws DataSourceException {        try {            ensureConnection();            DatabaseMetaData dmd = connection.getMetaData();            return dmd.getProcedureTerm();        }        catch (SQLException e) {            throw new DataSourceException(e);        }    }    public String[] getProcedureNames(String catalog, String schema, String name)        throws DataSourceException {        ResultSet rs = null;        try {            ensureConnection();                        DatabaseMetaData dmd = connection.getMetaData();            rs = dmd.getProcedures(catalog, schema, name);            List list = new ArrayList();                        while (rs.next()) {                list.add(rs.getString(3));            }            return (String[])list.toArray(new String[list.size()]);        }        catch (SQLException e) {            throw new DataSourceException(e);        }        finally {            releaseResources(rs);        }     }        public String[] getTables(String catalog, String schema, String metaType)        throws DataSourceException {        ResultSet rs = null;        try {            ensureConnection();            DatabaseMetaData dmd = connection.getMetaData();                        rs = dmd.getTables(catalog, schema, null, new String[]{metaType});            if (rs != null) { // some odd null rs behaviour on some drivers                ArrayList list = new ArrayList();                while (rs.next()) {                    list.add(rs.getString(3));                }                return (String[])list.toArray(new String[list.size()]);            }            else {                return new String[0];            }        }        catch (SQLException e) {            throw new DataSourceException(e);        }        finally {            releaseResources(rs);        }             }        /** <p>Executes the specified query (SELECT) and returns     *  a <code>ResultSet</code> object from this query.     *  <p>This is employed primarily by the Database Browser     *  to populate the 'Data' tab.     *     *  @param  the SQL query to execute     *  @return the query result     */    /*    public ResultSet getResultSet(String query) throws Exception {        Statement stmnt = null;                try {            ensureConnection();            stmnt = connection.createStatement();            return stmnt.executeQuery(query);                    }         catch (SQLException e) {            return null;        }         catch (OutOfMemoryError e) {            return null;        }                 finally {            try {                if (stmnt != null) {                    stmnt.close();                }            }            catch (SQLException sqlExc) {}            releaseResources();        }             }*/        // ----------------------------------------------------------    // convenience methods for simple values from the connection    // ----------------------------------------------------------        /** <p>Retrieves the connected data source name.     *  @return the data source name     */    public String getDataSourceName() {        String name = databaseConnection.getSourceName();        return name == null ? "Not Available" : name.toUpperCase();    }        /** <p>Retrieves the connected port number.     *  @return the port number     */    public int getPort() {        return databaseConnection.getPortInt();    }        /** <p>Retrieves the connected user.     *  @return the user name     */    public String getUser() {        return databaseConnection.getUserName();    }        /** <p>Retrieves the connected JDBC URL.     *  @return the JDBC URL     */    public String getURL() {        return getDataSource().getJdbcUrl();    }        /** <p>Retrieves the connected host name.     *  @return the host name     */    public String getHost() {        String host = databaseConnection.getHost();        return host == null ? "Not Available" : host.toUpperCase();    }      /**      * Retrieves the connected schema name.     *     * @return the schema name     */    public String getSchemaName() {        String schema = databaseConnection.getUserName();        return schema == null ? "Not Available" : schema.toUpperCase();    }        public String getCatalogName() {        String catalog = null;                try {            ensureConnection();            catalog = connection.getCatalog();            if (MiscUtils.isNull(catalog)) {                catalog = getSchemaName();            }        }        catch (SQLException e) {}        catch (DataSourceException e) {}        finally {            releaseResources();        }                return catalog == null ? "Not Available" : catalog.toUpperCase();    }        private ConnectionDataSource getDataSource() {        return (ConnectionDataSource)                    ConnectionManager.getDataSource(databaseConnection);    }    /**     * Indicates a connection has been established.     *      * @param the encapsulating event     */    public void connected(ConnectionEvent connectionEvent) {}    /**     * Indicates a connection has been closed.     *      * @param the encapsulating event     */    public void disconnected(ConnectionEvent connectionEvent) {        DatabaseConnection dc = connectionEvent.getSource();        if (connections.containsKey(dc)) {            connections.remove(dc);            // null out the connection if its the one disconnected            if (databaseConnection == dc) {                connection = null;            }        }    }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -