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

📄 databasemetadata.java

📁 用java访问MySQL数据库的JDBC驱动程序。
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     * @return max columns
     */
    
    public int getMaxColumnsInTable() throws java.sql.SQLException 
    {
        return 512;
    }
    
    /**
     * How many active connections can we have at a time to this database?
     *
     * @return max connections
     */
    
    public int getMaxConnections() throws java.sql.SQLException 
    {
        return 0;
    }
    
    /**
     * What's the maximum cursor name length?
     *
     * @return max cursor name length in bytes
     */

    public int getMaxCursorNameLength() throws java.sql.SQLException 
    {
        return 64;
    }
    
    /**
     * What's the maximum length of an index (in bytes)?
     *
     * @return max index length in bytes
     */
    
    public int getMaxIndexLength() throws java.sql.SQLException 
    {
        return 128;
    }
    
    /**
     * What's the maximum length allowed for a schema name?
     *
     * @return max name length in bytes
     */

    public int getMaxSchemaNameLength() throws java.sql.SQLException 
    {
        return 0;
    }

    /**
     * What's the maximum length of a procedure name?
     *
     * @return max name length in bytes
     */

    public int getMaxProcedureNameLength() throws java.sql.SQLException 
    {
        return 0;
    }

    /**
     * What's the maximum length of a catalog name?
     *
     * @return max name length in bytes
     */

    public int getMaxCatalogNameLength() throws java.sql.SQLException 
    {
        return 32;
    }

    /**
     * What's the maximum length of a single row?
     *
     * @return max row size in bytes
     */

    public int getMaxRowSize() throws java.sql.SQLException 
    {
        return Integer.MAX_VALUE - 8; // Max buffer size - HEADER
    }

    /**
     * Did getMaxRowSize() include LONGVARCHAR and LONGVARBINARY
     * blobs?
     *
     * @return true if so
     */

    public boolean doesMaxRowSizeIncludeBlobs() throws java.sql.SQLException 
    {
        return true;
    }

    /**
     * What's the maximum length of a SQL statement?
     *
     * @return max length in bytes
     */

    public int getMaxStatementLength() throws java.sql.SQLException 
    {
        return MysqlIO.MAXBUF - 4; // Max buffer - header
    }

    /**
     * How many active statements can we have open at one time to this
     * database?
     *
     * @return the maximum
     */

    public int getMaxStatements() throws java.sql.SQLException 
    {
        return 0;
    }

    /**
     * What's the maximum length of a table name?
     *
     * @return max name length in bytes
     */

    public int getMaxTableNameLength() throws java.sql.SQLException 
    {
        return 32;
    }

    /**
     * What's the maximum number of tables in a SELECT?
     *
     * @return the maximum
     */

    public int getMaxTablesInSelect() throws java.sql.SQLException 
    {
        return 256;
    }

    /**
     * What's the maximum length of a user name?
     *
     * @return max name length  in bytes
     */

    public int getMaxUserNameLength() throws java.sql.SQLException 
    {
        return 16;
    }

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

    /**
     * What's the database's default transaction isolation level?  The
     * values are defined in java.sql.Connection.
     *
     * @return the default isolation level
     * @see Connection
     */

    public int getDefaultTransactionIsolation() throws java.sql.SQLException 
    {
        return java.sql.Connection.TRANSACTION_NONE;
    }

    /**
     * Are transactions supported? If not, commit is a noop and the
     * isolation level is TRANSACTION_NONE.
     *
     * @return true if transactions are supported
     */

    public boolean supportsTransactions() throws java.sql.SQLException 
    {
        return false;
    }

    /**
     * Does the database support the given transaction isolation level?
     *
     * @param level the values are defined in java.sql.Connection
     * @return true if so
     * @see Connection
     */

    public boolean supportsTransactionIsolationLevel(int level)
        throws java.sql.SQLException 
    {
        return false;
    }

    /**
     * Are both data definition and data manipulation statements
     * within a transaction supported?
     *
     * @return true if so
     */

    public boolean supportsDataDefinitionAndDataManipulationTransactions()
        throws java.sql.SQLException 
    {
        return false;
    }

    /**
     * Are only data manipulation statements within a transaction
     * supported?
     *
     * @return true if so
     */

    public boolean supportsDataManipulationTransactionsOnly()
        throws java.sql.SQLException 
    {
        return false;
    }

    /**
     * Does a data definition statement within a transaction force the
     * transaction to commit?
     *
     * @return true if so
     */

    public boolean dataDefinitionCausesTransactionCommit()
        throws java.sql.SQLException 
    {
        return false;
    }

    /**
     * Is a data definition statement within a transaction ignored?
     *
     * @return true if so
     */

    public boolean dataDefinitionIgnoredInTransactions()
        throws java.sql.SQLException 
    {
        return false;
    }

    /**
     * Get a description of stored procedures available in a
     * catalog.
     *
     * <P>Only procedure descriptions matching the schema and
     * procedure name criteria are returned.  They are ordered by
     * PROCEDURE_SCHEM, and PROCEDURE_NAME.
     *
     * <P>Each procedure description has the the following columns:
     *  <OL>
     *    <LI><B>PROCEDURE_CAT</B> String => procedure catalog (may be null)
     *    <LI><B>PROCEDURE_SCHEM</B> String => procedure schema (may be null)
     *    <LI><B>PROCEDURE_NAME</B> String => procedure name
     *  <LI> reserved for future use
     *  <LI> reserved for future use
     *  <LI> reserved for future use
     *    <LI><B>REMARKS</B> String => explanatory comment on the procedure
     *    <LI><B>PROCEDURE_TYPE</B> short => kind of procedure:
     *      <UL>
     *      <LI> procedureResultUnknown - May return a result
     *      <LI> procedureNoResult - Does not return a result
     *      <LI> procedureReturnsResult - Returns a result
     *      </UL>
     *  </OL>
     *
     * @param catalog a catalog name; "" retrieves those without a catalog
     * @param schemaPattern a schema name pattern; "" retrieves those
     * without a schema
     * @param procedureNamePattern a procedure name pattern
     * @return ResultSet each row is a procedure description
     * @see #getSearchStringEscape
     */

    public java.sql.ResultSet getProcedures(String catalog, String schemaPattern,
					    String procedureNamePattern) throws java.sql.SQLException 
    {
	Field[] Fields = new Field[8];

	Fields[0]  = new Field("", "PROCEDURE_CAT",   Types.CHAR,     0);
	Fields[1]  = new Field("", "PROCEDURE_SCHEM", Types.CHAR,     0);
	Fields[2]  = new Field("", "PROCEDURE_NAME",  Types.CHAR,     0);
	Fields[3]  = new Field("", "resTABLE_CAT",    Types.CHAR,     0);
	Fields[4]  = new Field("", "resTABLE_CAT",    Types.CHAR,     0);
	Fields[5]  = new Field("", "resTABLE_CAT",    Types.CHAR,     0);
	Fields[6]  = new Field("", "REMARKS",         Types.CHAR,     0);
	Fields[7]  = new Field("", "PROCEDURE_TYPE",  Types.SMALLINT, 0);

	return new ResultSet(Fields, new Vector(), _Conn);
    }

    /**
     * Get a description of a catalog's stored procedure parameters
     * and result columns.
     *
     * <P>Only descriptions matching the schema, procedure and
     * parameter name criteria are returned.  They are ordered by
     * PROCEDURE_SCHEM and PROCEDURE_NAME. Within this, the return value,
     * if any, is first. Next are the parameter descriptions in call
     * order. The column descriptions follow in column number order.
     *
     * <P>Each row in the ResultSet is a parameter desription or
     * column description with the following fields:
     *  <OL>
     *    <LI><B>PROCEDURE_CAT</B> String => procedure catalog (may be null)
     *    <LI><B>PROCEDURE_SCHEM</B> String => procedure schema (may be null)
     *    <LI><B>PROCEDURE_NAME</B> String => procedure name
     *    <LI><B>COLUMN_NAME</B> String => column/parameter name
     *    <LI><B>COLUMN_TYPE</B> Short => kind of column/parameter:
     *      <UL>
     *      <LI> procedureColumnUnknown - nobody knows
     *      <LI> procedureColumnIn - IN parameter
     *      <LI> procedureColumnInOut - INOUT parameter
     *      <LI> procedureColumnOut - OUT parameter
     *      <LI> procedureColumnReturn - procedure return value
     *      <LI> procedureColumnResult - result column in ResultSet
     *      </UL>
     *  <LI><B>DATA_TYPE</B> short => SQL type from java.sql.Types
     *    <LI><B>TYPE_NAME</B> String => SQL type name
     *    <LI><B>PRECISION</B> int => precision
     *    <LI><B>LENGTH</B> int => length in bytes of data
     *    <LI><B>SCALE</B> short => scale
     *    <LI><B>RADIX</B> short => radix
     *    <LI><B>NULLABLE</B> short => can it contain NULL?
     *      <UL>
     *      <LI> procedureNoNulls - does not allow NULL values
     *      <LI> procedureNullable - allows NULL values
     *      <LI> procedureNullableUnknown - nullability unknown
     *      </UL>
     *    <LI><B>REMARKS</B> String => comment describing parameter/column
     *  </OL>
     *
     * <P><B>Note:</B> Some databases may not return the column
     * descriptions for a procedure. Additional columns beyond
     * REMARKS can be defined by the database.
     *
     * @param catalog a catalog name; "" retrieves those without a catalog
     * @param schemaPattern a schema name pattern; "" retrieves those
     * without a schema
     * @param procedureNamePattern a procedure name pattern
     * @param columnNamePattern a column name pattern
     * @return ResultSet each row is a stored procedure parameter or
     *      column description
     * @see #getSearchStringEscape
     */

    public java.sql.ResultSet getProcedureColumns(String Catalog,
						  String SchemaPattern,
						  String ProcedureNamePattern,
						  String ColumnNamePattern) throws java.sql.SQLException 
    {
	Field[] Fields = new Field[14];
    
	Fields[0]  = new Field("", "TABLE_CAT",       Types.CHAR,     0);
	Fields[1]  = new Field("", "PROCEDURE_CAT",   Types.CHAR,     0);
	Fields[2]  = new Field("", "PROCEDURE_SCHEM", Types.CHAR,     0);
	Fields[3]  = new Field("", "PROCEDURE_NAME",  Types.CHAR,     0);
	Fields[4]  = new Field("", "COLUMN_NAME",     Types.CHAR,     0);
	Fields[5]  = new Field("", "COLUMN_TYPE",     Types.CHAR,     0);
	Fields[6]  = new Field("", "DATA_TYPE",       Types.SMALLINT, 0);
	Fields[7]  = new Field("", "TYPE_NAME",       Types.CHAR,     0);
	Fields[8]  = new Field("", "PRECISION",       Types.INTEGER,  0);
	Fields[9]  = new Field("", "LENGTH",          Types.INTEGER,  0);
	Fields[10] = new Field("", "SCALE",           Types.SMALLINT, 0);
	Fields[11] = new Field("", "RADIX",           Types.SMALLINT, 0);
	Fields[12] = new Field("", "NULLABLE",        Types.SMALLINT, 0);
	Fields[13] = new Field("", "REMARKS",         Types.CHAR,     0);
		
	return new ResultSet(Fields, new Vector(), _Conn);
    }

    /**
     * Get a description of tables available in a catalog.
     *
     * <P>Only table descriptions matching the catalog, schema, table
     * name and type criteria are returned.  They are ordered by
     * TABLE_TYPE, TABLE_SCHEM and TABLE_NAME.
     *
     * <P>Each table description has the following columns:
     *  <OL>
     *    <LI><B>TABLE_CAT</B> String => table catalog (may be null)
     *    <LI><B>TABLE_SCHEM</B> String => table schema (may be null)
     *    <LI><B>TABLE_NAME</B> String => table name
     *    <LI><B>TABLE_TYPE</B> String => table type.  Typical types are "TABLE",
     *                    "VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY",
     *                    "LOCAL TEMPORARY", "ALIAS", "SYNONYM".
     *    <LI><B>REMARKS</B> String => explanatory comment on the table
     *  </OL>
     *
     * <P><B>Note:</B> Some databases may not return information for
     * all tables.
     *
     * @param catalog a catalog name; "" retrieves those without a catalog
     * @param schemaPattern a schema name pattern; "" retrieves those
     * without a schema
     * @param tableNamePattern a table name pattern
     * @param types a list of table types to include; null returns all types
     * @return ResultSet each row is a table description
     * @see #getSearchStringEscape
     */

    public java.sql.ResultSet getTables(String Catalog, String SchemaPattern, 
					String TableNamePattern, 
					String Types[])
	throws java.sql.SQLException
    {

	String DB_Sub = "";

	if (Catalog != null) {
	    if (!Catalog.equals("")) {
		DB_Sub = " FROM " + Catalog;
	    }
	}
	else {
	    DB_Sub = " FROM " + _Database;
	}

	if (TableNamePattern == null) {
	    TableNamePattern = "%";
	}
		
	java.sql.ResultSet RS = _Conn.createStatement().executeQuery(
								     "show tables " + DB_Sub + " like '" 
								     + TableNamePattern + "'");

	java.sql.ResultSetMetaData RsMd = RS.getMetaData();
    
	Field[] Fields = new Field[5];

	Fields[0] = new  Field("", "TABLE_CAT",   java.sql.Types.VARCHAR, 
			       (Catalog == null) ? 0 : Catalog.length());
	Fields[1] = new  Field("", "TABLE_SCHEM", java.sql.Types.VARCHAR, 0);
	Fields[2] = new  Field("", "TABLE_NAME",  java.sql.Types.VARCHAR, 255);
	Fields[3] = new  Field("", "TABLE_TYPE",  java.sql.Types.VARCHAR, 5);
	Fields[4] = new  Field("", "REMARKS",     java.sql.Types.VARCHAR, 0);

	Vector Tuples = new Vector();

	byte[][] Row = null;
    
	while (RS.next()) {
    
	    String Name = RS.getString(1);
		 
	    Row = new byte[5][];
	    Row[0] = (Catalog == null) ? new byte[0]:Catalog.getBytes();
	    Row[1] = new byte[0];
	    Row[2] = Name.getBytes();
	    Row[3] = _Table_As_Bytes;
	    Row[4] = new byte[0];
	    Tuples.addElement(Row);
	} 

	ResultSet Results = new ResultSet(Fields, Tuples, _Conn);
		  
	return Results;
    }
  
    /**
     * Get the schema names available in this database.  The results

⌨️ 快捷键说明

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