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

📄 metadatavalues.java

📁 eq跨平台查询工具源码 eq跨平台查询工具源码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                sb.append(schema);                sb.append(".");            }            sb.append(table);                        stmnt = connection.createStatement();            rs = stmnt.executeQuery(sb.toString());            if (rs.next()) {                return rs.getInt(1);            }            return 0;        }        catch (SQLException e) {            throw new DataSourceException(e);        }        finally {            releaseResources(stmnt, rs);        }     }        public boolean hasStoredObjects(String schema, String[] types)        throws DataSourceException {        return hasStoredObjects(null, schema, types);    }    public boolean hasStoredObjects(String catalog, String schema, String[] types)         throws DataSourceException {        if (schema == null) {            schema = getSchemaName();        }        ResultSet rs = null;        try {            ensureConnection();            DatabaseMetaData dmd = connection.getMetaData();            rs = dmd.getTables(catalog, schema, null, types);            return rs.next();                    }        catch (SQLException e) {            throw new DataSourceException(e);        }        finally {            releaseResources(rs);        }    }    public DatabaseProcedure[] getStoredObjects(String schema, String[] types)        throws DataSourceException {        return getStoredObjects(null, schema, types);    }        public DatabaseProcedure[] getStoredObjects(            String catalog, String schema, String[] types) throws DataSourceException {        ResultSet rs = null;        if (schema == null) {            schema = getSchemaName();        }                try {            ensureConnection();            DatabaseMetaData dmd = connection.getMetaData();            rs = dmd.getTables(catalog, schema, null, types);                        ArrayList list = new ArrayList();                        while (rs.next()) {                list.add(rs.getString(3));            }                        rs.close();                        String[] procedures = (String[])list.toArray(new String[list.size()]);            list.clear();                        for (int i = 0; i < procedures.length; i++) {                                rs = dmd.getProcedures(null, schema, procedures[i]);                                while (rs.next()) {                    String name = rs.getString(3);                    DatabaseProcedure dbproc = new DatabaseProcedure(                            rs.getString(2),                            name);                                        ResultSet _rs = dmd.getProcedureColumns(null, schema, name, null);                    while (_rs.next()) {                        dbproc.addParameter(_rs.getString(4),                                            _rs.getInt(5),                                            _rs.getInt(6),                                            _rs.getString(7),                                            _rs.getInt(8));                    }                                        _rs.close();                    list.add(dbproc);                }                             }                         DatabaseProcedure[] procs =                     (DatabaseProcedure[])list.toArray(new DatabaseProcedure[list.size()]);            return procs;                    }        catch (SQLException e) {            throw new DataSourceException(e);        }        finally {            releaseResources(rs);        }             }    /**     * Recycles the specified connection object.     *     * @param dc - the connection to be recycled     */    public void recycleConnection(DatabaseConnection dc)         throws DataSourceException {        if (connections.containsKey(dc)) {            //Log.debug("Recycling connection");            // close the connection held in the local cache            // another will be retrieved on the next call to it            Connection c = connections.get(dc);            ConnectionManager.close(dc, c);            connections.put(dc, null);        }    }    /**      * Closes the open connection and releases     * all resources attached to it.     */    public void closeConnection() {        try {            for (Iterator i = connections.keySet().iterator(); i.hasNext();) {                DatabaseConnection dc = (DatabaseConnection)i.next();                connection = connections.get(dc);                if (connection != null) {                    connection.close();                }                connection = null;            }            /*            if (connection != null) {                connection.close();            }            connection = null;             */        }         catch (SQLException sqlExc) {            sqlExc.printStackTrace();        }    }        /** <p>Retrieves key/value type pairs using the     *  <code>Reflection</code> API to call and retrieve     *  values from the connection's meta data object's methods     *  and variables.     *  <p>The values are returned within a 2-dimensional     *  array of key/value pairs.     *     *  @return the database properties as key/value pairs     */    public Hashtable getDatabaseProperties() throws DataSourceException {        try {                        ensureConnection();            DatabaseMetaData dmd = connection.getMetaData();                        Class metaClass = dmd.getClass();            Method[] metaMethods = metaClass.getMethods();                        Object[] p = new Object[] {};                        Hashtable h = new Hashtable();            String STRING = "String";            String GET = "get";                        for (int i = 0; i < metaMethods.length; i++) {                try {                    Class c = metaMethods[i].getReturnType();                    String s = metaMethods[i].getName();                                        if (s == null || c == null) {                        continue;                    }                    if (c.isPrimitive() || c.getName().endsWith(STRING)) {                                                if (s.startsWith(GET)) {                            s = s.substring(3);                        }                                                try {                            Object res = metaMethods[i].invoke(dmd, p);                            h.put(s, res.toString());                        } catch (AbstractMethodError abe) {                            continue;                        }                                             }                 } catch (Exception e) {                    continue;                }             }/*                        int count = 0;            // prepare for key sort            String[] keys = new String[h.size()];            for (Enumeration i = h.keys(); i.hasMoreElements();) {                keys[count++] = (String)i.nextElement();            }                        Arrays.sort(keys);            String[][] dbData = new String[keys.length][2];            for (int i = 0; i < keys.length; i++) {                dbData[i][0] = keys[i];                dbData[i][1] = (String)h.get(keys[i]);            }*/            return h;                    }        catch (SQLException e) {            throw new DataSourceException(e);        }        finally {            releaseResources();        }             }        /** <p>Retrieves the connected databases SQL keyword     *  list via a call to the <code>DatabaseMetaData</code>     *  object's <code>getSQLKeywords()</code> method.     *  <p>The retrieved keywords are stored within a     *  2-dimensional array for display with the relevant     *  header within a table.     *     *  @return the schema names array     */    public String[] getDatabaseKeywords() throws DataSourceException {        try {            ensureConnection();            DatabaseMetaData dmd = connection.getMetaData();                        String sql = dmd.getSQLKeywords();            releaseResources();                        StringTokenizer st = new StringTokenizer(sql, ",");            List<String> values = new ArrayList<String>();                        while(st.hasMoreTokens()) {                values.add(st.nextToken());            }                         int size = values.size();            String[] words = new String[size];            for (int i =0; i < size; i++) {                words[i] = values.get(i);            }             return words;                    }         catch (SQLException e) {            throw new DataSourceException(e);        }    }    private void releaseResources(Statement stmnt) {        try {            if (stmnt != null) {                stmnt.close();            }        }        catch (SQLException sqlExc) {}        finally {            releaseResources();        }    }    private void releaseResources(Statement stmnt, ResultSet rs) {        try {            if (rs != null) {                rs.close();            }                        if (stmnt != null) {                stmnt.close();            }        }        catch (SQLException sqlExc) {}        finally {            releaseResources();        }    }    private void releaseResources(ResultSet rs) {        try {            if (rs != null) {                rs.close();            }        }        catch (SQLException sqlExc) {}        finally {            releaseResources();        }    }       /** <p>Releases this object's connection resources */    private void releaseResources() {        if (keepAlive) {            return;        }        closeConnection();    }        /** <p>Retrieves the database SQL data types as a     *  <code>ResultSet</code> object.     *  <p>This will be typically used to display the     *  complete data types meta data retrieved from the JDBC driver.     *     *  @return the SQL data types     */    public ResultSet getDataTypesResultSet() throws DataSourceException {        try {            ensureConnection();            DatabaseMetaData dmd = connection.getMetaData();            return dmd.getTypeInfo();        }         catch (SQLException e) {            throw new DataSourceException(e);        }    }    /** <p>Retrieves the database SQL data type names only.     *     *  @return the SQL data type names within an array     */    public String[] getDataTypesArray() throws DataSourceException {        ResultSet rs = null;        try {            ensureConnection();                        DatabaseMetaData dmd = connection.getMetaData();            rs = dmd.getTypeInfo();            String underscore = "_";            List<String> _dataTypes = new ArrayList<String>();            while (rs.next()) {                String type = rs.getString(1);                if (!type.startsWith(underscore)) {                    _dataTypes.add(type);                }                            }             int size = _dataTypes.size();            String[] dataTypes = new String[size];                        for (int i = 0; i < size; i++) {                dataTypes[i] = _dataTypes.get(i);            }                         Arrays.sort(dataTypes);            return dataTypes;        }         catch (SQLException e) {            throw new DataSourceException(e);        }        finally {            releaseResources(rs);        }             }        /** <p>Retrieves the currently connected schema's     *  database table names within a <code>Vector</code>.     *     *  @return the table names     */    public Vector getDatabaseTablesVector() throws DataSourceException {        ResultSet rs = null;        try {            ensureConnection();                        DatabaseMetaData dmd = connection.getMetaData();            String[] type = {"TABLE"};            rs = dmd.getTables(null,                               getSchemaName(),                               null,                                type);                        Vector v = new Vector();            while (rs.next()) {                v.add(rs.getString(3));            }                        return v;        }         catch (SQLException e) {            throw new DataSourceException(e);        }                finally {            releaseResources(rs);        }             }        /** <p>Retrieves the column names for the specified     *  database table and schema as an array.     *     *  @param the database table name     *  @param the database schema name     *  @return the column names array     */    public String[] getColumnNames(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));            }                         int v_size = v.size();            String[] columns = new String[v_size];            for (int i = 0; i < v_size; i++) {                columns[i] = v.get(i);            }                         return columns;        }                 catch (SQLException e) {            throw new DataSourceException(e);

⌨️ 快捷键说明

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