📄 databasemetadata.java
字号:
* 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
{
if (_conn.supportsIsolationLevel())
{
return java.sql.Connection.TRANSACTION_READ_COMMITTED;
}
else
{
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 _conn.supportsTransactions();
}
/**
* 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
{
if (_conn.supportsIsolationLevel())
{
switch (level)
{
case java.sql.Connection.TRANSACTION_READ_COMMITTED :
case java.sql.Connection.TRANSACTION_READ_UNCOMMITTED :
case java.sql.Connection.TRANSACTION_REPEATABLE_READ :
case java.sql.Connection.TRANSACTION_SERIALIZABLE :
return true;
default :
return false;
}
}
else
{
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 buildResultSet(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 buildResultSet(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 " + _quotedId + Catalog + _quotedId;
}
}
else
{
DB_Sub = " FROM " + _quotedId + _database + _quotedId;
}
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);
}
java.sql.ResultSet Results = buildResultSet(Fields, Tuples, _conn);
return Results;
}
/**
* Get the schema names available in this database. The results
* are ordered by schema name.
*
* <P>The schema column is:
* <OL>
* <LI><B>TABLE_SCHEM</B> String => schema name
* </OL>
*
* @return ResultSet each row has a single String column that is a
* schema name
*/
public java.sql.ResultSet getSchemas() throws java.sql.SQLException
{
Field[] Fields = new Field[1];
Fields[0] = new Field("", "TABLE_SCHEM", java.sql.Types.CHAR, 0);
Vector Tuples = new Vector();
java.sql.ResultSet RS = buildResultSet(Fields, Tuples, _conn);
return RS;
}
/**
* Get the catalog names available in this database. The results
* are ordered by catalog name.
*
* <P>The catalog column is:
* <OL>
* <LI><B>TABLE_CAT</B> String => catalog name
* </OL>
*
* @return ResultSet each row has a single String column that is a
* catalog name
*/
public java.sql.ResultSet getCatalogs() throws java.sql.SQLException
{
java.sql.ResultSet RS = _conn.createStatement().executeQuery("SHOW DATABASES");
java.sql.ResultSetMetaData RSMD = RS.getMetaData();
Field[] Fields = new Field[1];
Fields[0] =
new Field("", "TABLE_CAT", Types.VARCHAR, RSMD.getColumnDisplaySize(1));
Vector Tuples = new Vector();
while (RS.next())
{
byte[][] RowVal = new byte[1][];
RowVal[0] = RS.getBytes(1);
Tuples.addElement(RowVal);
}
return buildResultSet(Fields, Tuples, _conn);
}
/**
* Get the table types available in this database. The results
* are ordered by table type.
*
* <P>The table type is:
* <OL>
* <LI><B>TABLE_TYPE</B> String => table type. Typical types are "TABLE",
* "VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY",
* "LOCAL TEMPORARY", "ALIAS", "SYNONYM".
* </OL>
*
* @return ResultSet each row has a single String column that is a
* table type
*/
public java.sql.ResultSet getTableTypes() throws java.sql.SQLException
{
Vector Tuples = new Vector();
Field[] Fields = new Field[1];
Fields[0] = new Field("", "TABLE_TYPE", Types.VARCHAR, 5);
byte[][] TType = new byte[1][];
TType[0] = _TABLE_AS_BYTES;
Tuples.addElement(TType);
return buildResultSet(Fields, Tuples, _conn);
}
/**
* Get a description of table columns available in a catalog.
*
* <P>Only column descriptions matching the catalog, schema, table
* and column name criteria are returned. They are ordered by
* TABLE_SCHEM, TABLE_NAME and ORDINAL_POSITION.
*
* <P>Each column 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>COLUMN_NAME</B> String => column name
* <LI><B>DATA_TYPE</B> short => SQL type from java.sql.Types
* <LI><B>TYPE_NAME</B> String => Data source dependent type name
* <LI><B>COLUMN_SIZE</B> int => column size. For char or date
* types this is the maximum number of characters, for numeric or
* decimal types this is precision.
* <LI><B>BUFFER_LENGTH</B> is not used.
* <LI><B>DECIMAL_DIGITS</B> int => the number of fractional digits
* <LI><B>NUM_PREC_RADIX</B> int => Radix (typically either 10 or 2)
* <LI><B>NULLABLE</B> int => is NULL allowed?
* <UL>
* <LI> columnNoNulls - might not allow NULL values
* <LI> columnNullable - definitely allows NULL values
* <LI> columnNullableUnknown - nullability unknown
* </UL>
* <LI><B>REMARKS</B> String => comment describing column (may be null)
* <LI><B>COLUMN_DEF</B> String => default value (may be null)
* <LI><B>SQL_DATA_TYPE</B> int => unused
* <LI><B>SQL_DATETIME_SUB</B> int => unused
* <LI><B>CHAR_OCTET_LENGTH</B> int => for char types the
* maximum number of bytes in the column
* <LI><B>ORDINAL_POSITION</B> int => index of column in table
* (starting at 1)
* <LI><B>IS_NULLABLE</B> String => "NO" means column definitely
* does not allow NULL values; "YES" means the column might
* allow NULL values. An empty string means nobody knows.
* </OL>
*
* @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 columnNamePattern a column name pattern
* @return ResultSet each row is a column description
* @see #getSearchStringEscape
*/
public java.sql.ResultSet getColumns(
String Catalog,
String SchemaPattern,
String TableName,
String ColumnNamePattern)
throws java.sql.SQLException
{
String DB_Sub = "";
if (ColumnNamePattern == null)
{
ColumnNamePattern = "%";
}
if (Catalog != null)
{
if (!Catalog.equals(""))
{
DB_Sub = " FROM " + _quotedId + Catalog + _quotedId;
}
}
else
{
DB_Sub = " FROM " + _quotedId + _database + _quotedId;
}
Vector TableNameList = new Vector();
int tablename_length = 0;
if (TableName == null)
{
// Select from all tables
java.sql.ResultSet Tables =
getTables(Catalog, SchemaPattern, "%", new String[0]);
while (Tables.next())
{
String TN = Tables.getString("TABLE_NAME");
TableNameList.addElement(TN);
if (TN.length() > tablename_length)
{
tablename_length = TN.length();
}
}
Tables.close();
}
else
{
java.sql.ResultSet Tables =
getTables(Catalog, SchemaPattern, TableName, new String[0]);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -