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

📄 databasemetadata.java

📁 jsp数据库系统
💻 JAVA
📖 第 1 页 / 共 5 页
字号:

                    for (int i = 0; i < tuples.size(); i++) {
                        byte[][] b = (byte[][]) tuples.get(i);
                        rows.append("[Row] ");

                        boolean firstTime = true;

                        for (int j = 0; j < b.length; j++) {
                            if (!firstTime) {
                                rows.append(", ");
                            } else {
                                firstTime = false;
                            }

                            if (b[j] == null) {
                                rows.append("null");
                            } else {
                                rows.append(new String(b[j]));
                            }
                        }

                        rows.append("\n");
                    }

                    Debug.returnValue(this, "getCrossReference", rows.toString());
                }

                return buildResultSet(fields, tuples);
            } finally {
                if (fkresults != null) {
                    try {
                        fkresults.close();
                    } catch (Exception sqlEx) {
                        AssertionFailedException.shouldNotHappen(sqlEx);
                    }

                    fkresults = null;
                }

                if (stmt != null) {
                    try {
                        stmt.close();
                    } catch (Exception ex) {
                        ;
                    }

                    stmt = null;
                }
            }
        } else {
            return buildResultSet(fields, new ArrayList());
        }
    }

    /**
     * @see DatabaseMetaData#getDatabaseMajorVersion()
     */
    public int getDatabaseMajorVersion() throws SQLException {
        return this.conn.getServerMajorVersion();
    }

    /**
     * @see DatabaseMetaData#getDatabaseMinorVersion()
     */
    public int getDatabaseMinorVersion() throws SQLException {
        return this.conn.getServerMinorVersion();
    }

    /**
     * What's the name of this database product?
     *
     * @return database product name
     *
     * @throws java.sql.SQLException DOCUMENT ME!
     */
    public String getDatabaseProductName() throws java.sql.SQLException {
        return "MySQL";
    }

    /**
     * What's the version of this database product?
     *
     * @return database version
     *
     * @throws java.sql.SQLException DOCUMENT ME!
     */
    public String getDatabaseProductVersion() throws java.sql.SQLException {
        return this.conn.getServerVersion();
    }

    //----------------------------------------------------------------------

    /**
     * What's the database's default transaction isolation level?  The values
     * are defined in java.sql.Connection.
     *
     * @return the default isolation level
     *
     * @throws java.sql.SQLException if a database access error occurs
     *
     * @see Connection
     */
    public int getDefaultTransactionIsolation() throws java.sql.SQLException {
        if (this.conn.supportsIsolationLevel()) {
            return java.sql.Connection.TRANSACTION_READ_COMMITTED;
        } else {
            return java.sql.Connection.TRANSACTION_NONE;
        }
    }

    /**
     * What's this JDBC driver's major version number?
     *
     * @return JDBC driver major version
     */
    public int getDriverMajorVersion() {
        return Driver.getMajorVersionInternal();
    }

    /**
     * What's this JDBC driver's minor version number?
     *
     * @return JDBC driver minor version number
     */
    public int getDriverMinorVersion() {
        return Driver.getMinorVersionInternal();
    }

    /**
     * What's the name of this JDBC driver?
     *
     * @return JDBC driver name
     *
     * @throws java.sql.SQLException DOCUMENT ME!
     */
    public String getDriverName() throws java.sql.SQLException {
        return "MySQL-AB JDBC Driver";
    }

    /**
     * What's the version of this JDBC driver?
     *
     * @return JDBC driver version
     *
     * @throws java.sql.SQLException DOCUMENT ME!
     */
    public String getDriverVersion() throws java.sql.SQLException {
        return "mysql-connector-java-3.0.11-stable ( $Date: 2004/02/04 02:47:36 $, $Revision: 1.27.2.34 $ )";
    }

    /**
     * Get a description of a foreign key columns that reference a table's
     * primary key columns (the foreign keys exported by a table).  They are
     * ordered by FKTABLE_CAT, FKTABLE_SCHEM, FKTABLE_NAME, and KEY_SEQ.
     * 
     * <P>
     * Each foreign key column description has the following columns:
     * 
     * <OL>
     * <li>
     * <B>PKTABLE_CAT</B> String => primary key table catalog (may be null)
     * </li>
     * <li>
     * <B>PKTABLE_SCHEM</B> String => primary key table schema (may be null)
     * </li>
     * <li>
     * <B>PKTABLE_NAME</B> String => primary key table name
     * </li>
     * <li>
     * <B>PKCOLUMN_NAME</B> String => primary key column name
     * </li>
     * <li>
     * <B>FKTABLE_CAT</B> String => foreign key table catalog (may be null)
     * being exported (may be null)
     * </li>
     * <li>
     * <B>FKTABLE_SCHEM</B> String => foreign key table schema (may be null)
     * being exported (may be null)
     * </li>
     * <li>
     * <B>FKTABLE_NAME</B> String => foreign key table name being exported
     * </li>
     * <li>
     * <B>FKCOLUMN_NAME</B> String => foreign key column name being exported
     * </li>
     * <li>
     * <B>KEY_SEQ</B> short => sequence number within foreign key
     * </li>
     * <li>
     * <B>UPDATE_RULE</B> short => What happens to foreign key when primary is
     * updated:
     * 
     * <UL>
     * <li>
     * importedKeyCascade - change imported key to agree with primary key
     * update
     * </li>
     * <li>
     * importedKeyRestrict - do not allow update of primary key if it has been
     * imported
     * </li>
     * <li>
     * importedKeySetNull - change imported key to NULL if its primary key has
     * been updated
     * </li>
     * </ul>
     * 
     * </li>
     * <li>
     * <B>DELETE_RULE</B> short => What happens to the foreign key when primary
     * is deleted.
     * 
     * <UL>
     * <li>
     * importedKeyCascade - delete rows that import a deleted key
     * </li>
     * <li>
     * importedKeyRestrict - do not allow delete of primary key if it has been
     * imported
     * </li>
     * <li>
     * importedKeySetNull - change imported key to NULL if its primary key has
     * been deleted
     * </li>
     * </ul>
     * 
     * </li>
     * <li>
     * <B>FK_NAME</B> String => foreign key identifier (may be null)
     * </li>
     * <li>
     * <B>PK_NAME</B> String => primary key identifier (may be null)
     * </li>
     * </ol>
     * </p>
     *
     * @param catalog a catalog name; "" retrieves those without a catalog
     * @param schema a schema name pattern; "" retrieves those without a schema
     * @param table a table name
     *
     * @return ResultSet each row is a foreign key column description
     *
     * @throws java.sql.SQLException if a database access error occurs
     *
     * @see #getImportedKeys
     */
    public java.sql.ResultSet getExportedKeys(String catalog, String schema,
        String table) throws java.sql.SQLException {
        if (Driver.TRACE) {
            Object[] args = { catalog, schema, table };
            Debug.methodCall(this, "getExportedKeys", args);
        }

        if (table == null) {
            throw new java.sql.SQLException("Table not specified.", SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
        }

        Field[] fields = new Field[14];
        fields[0] = new Field("", "PKTABLE_CAT", Types.CHAR, 255);
        fields[1] = new Field("", "PKTABLE_SCHEM", Types.CHAR, 0);
        fields[2] = new Field("", "PKTABLE_NAME", Types.CHAR, 255);
        fields[3] = new Field("", "PKCOLUMN_NAME", Types.CHAR, 32);
        fields[4] = new Field("", "FKTABLE_CAT", Types.CHAR, 255);
        fields[5] = new Field("", "FKTABLE_SCHEM", Types.CHAR, 0);
        fields[6] = new Field("", "FKTABLE_NAME", Types.CHAR, 255);
        fields[7] = new Field("", "FKCOLUMN_NAME", Types.CHAR, 32);
        fields[8] = new Field("", "KEY_SEQ", Types.SMALLINT, 2);
        fields[9] = new Field("", "UPDATE_RULE", Types.SMALLINT, 2);
        fields[10] = new Field("", "DELETE_RULE", Types.SMALLINT, 2);
        fields[11] = new Field("", "FK_NAME", Types.CHAR, 255);
        fields[12] = new Field("", "PK_NAME", Types.CHAR, 0);
        fields[13] = new Field("", "DEFERRABILITY", Types.INTEGER, 2);

        if (this.conn.getIO().versionMeetsMinimum(3, 23, 0)) {
            Statement stmt = null;
            ResultSet fkresults = null;

            try {
                /*
                 * Get foreign key information for table
                 */
                if (this.conn.getIO().versionMeetsMinimum(3, 23, 50)) {
                    // we can use 'SHOW CREATE TABLE'
                    String database = this.database;

                    if (catalog != null) {
                        if (!catalog.equals("")) {
                            database = catalog;
                        }
                    }

                    fkresults = extractForeignKeyFromCreateTable(this.conn,
                            this, database, null);
                } else {
                    String databasePart = "";

                    if (catalog != null) {
                        if (!catalog.equals("")) {
                            databasePart = " FROM " + catalog;
                        }
                    } else {
                        databasePart = " FROM " + this.database;
                    }

                    stmt = this.conn.createStatement();
                    
					if (stmt.getMaxRows() != 0) {
						stmt.setMaxRows(0);
					}
					
                    fkresults = stmt.executeQuery("show table status "
                            + databasePart);
                }

                // lower-case table name might be turned on
                String tableNameWithCase = getTableNameWithCase(table);

                /*
                * Parse imported foreign key information
                */
                ArrayList tuples = new ArrayList();

                while (fkresults.next()) {
                    String tableType = fkresults.getString("Type");

                    if ((tableType != null)
                            && (tableType.equalsIgnoreCase("innodb")
                            || tableType.equalsIgnoreCase(SUPPORTS_FK))) {
                        String comment = fkresults.getString("Comment").trim();

                        if (comment != null) {
                            StringTokenizer commentTokens = new StringTokenizer(comment,
                                    ";", false);

                            if (commentTokens.hasMoreTokens()) {
                                commentTokens.nextToken(); // Skip InnoDB comment

                                while (commentTokens.hasMoreTokens()) {
                                    String keys = commentTokens.nextToken();
                                    getExportKeyResults(catalog,
                                        tableNameWithCase, keys, tuples,
               

⌨️ 快捷键说明

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