📄 jtdsdatabasemetadata.java
字号:
* are defined in java.sql.Connection. * * @return the default isolation level * @throws SQLException if a database-access error occurs. * * @see Connection */ public int getDefaultTransactionIsolation() throws SQLException { return Connection.TRANSACTION_READ_COMMITTED; } /** * Returns this JDBC driver's major version number. * * @return JDBC driver major version */ public int getDriverMajorVersion() { return Driver.MAJOR_VERSION; } /** * Returns this JDBC driver's minor version number. * * @return JDBC driver minor version number */ public int getDriverMinorVersion() { return Driver.MINOR_VERSION; } /** * Returns the name of this JDBC driver. * * @return JDBC driver name * @throws SQLException if a database-access error occurs. */ public String getDriverName() throws SQLException { return "jTDS Type 4 JDBC Driver for MS SQL Server and Sybase"; } /** * Returns the version of this JDBC driver. * * @return JDBC driver version * @throws SQLException if a database-access error occurs. */ public String getDriverVersion() throws SQLException { return Driver.getVersion(); } /** * Get a description of the 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> <B>PKTABLE_SCHEM</B> String =>primary key table schema (may be * null) * <LI> <B>PKTABLE_NAME</B> String =>primary key table name * <LI> <B>PKCOLUMN_NAME</B> String =>primary key column name * <LI> <B>FKTABLE_CAT</B> String =>foreign key table catalog (may be * null) being exported (may be null) * <LI> <B>FKTABLE_SCHEM</B> String =>foreign key table schema (may be * null) being exported (may be null) * <LI> <B>FKTABLE_NAME</B> String =>foreign key table name being * exported * <LI> <B>FKCOLUMN_NAME</B> String =>foreign key column name being * exported * <LI> <B>KEY_SEQ</B> short =>sequence number within foreign key * <LI> <B>UPDATE_RULE</B> short =>What happens to foreign key when * primary is updated: * <UL> * <LI> importedNoAction - do not allow update of primary key if it has * been imported * <LI> importedKeyCascade - change imported key to agree with primary * key update * <LI> importedKeySetNull - change imported key to NULL if its primary * key has been updated * <LI> importedKeySetDefault - change imported key to default values * if its primary key has been updated * <LI> importedKeyRestrict - same as importedKeyNoAction (for ODBC 2.x * compatibility) * </UL> * * <LI> <B>DELETE_RULE</B> short =>What happens to the foreign key when * primary is deleted. * <UL> * <LI> importedKeyNoAction - do not allow delete of primary key if it * has been imported * <LI> importedKeyCascade - delete rows that import a deleted key * <LI> importedKeySetNull - change imported key to NULL if its primary * key has been deleted * <LI> importedKeyRestrict - same as importedKeyNoAction (for ODBC 2.x * compatibility) * <LI> importedKeySetDefault - change imported key to default if its * primary key has been deleted * </UL> * * <LI> <B>FK_NAME</B> String =>foreign key name (may be null) * <LI> <B>PK_NAME</B> String =>primary key name (may be null) * <LI> <B>DEFERRABILITY</B> short =>can the evaluation of foreign key * constraints be deferred until commit * <UL> * <LI> importedKeyInitiallyDeferred - see SQL92 for definition * <LI> importedKeyInitiallyImmediate - see SQL92 for definition * <LI> importedKeyNotDeferrable - see SQL92 for definition * </UL> * * </OL> * * * @param catalog a catalog name; "" retrieves those without a * <code>null</code> means drop catalog name from the selection criteria * @param schema a schema name; "" retrieves those without a schema * @param table a table name * @return ResultSet - each row is a foreign key column description * @throws SQLException if a database-access error occurs. * * @see #getImportedKeys */ public java.sql.ResultSet getExportedKeys(String catalog, String schema, String table) throws SQLException { return getCrossReference(catalog, schema, table, null, null, null); } /** * Get all the "extra" characters that can be used in unquoted identifier * names (those beyond a-z, A-Z, 0-9 and _). * * @return the string containing the extra characters * @throws SQLException if a database-access error occurs. */ public String getExtraNameCharacters() throws SQLException { // MS driver returns "$#@" Sybase JConnect returns "@#$%" return "$#@"; } /** * Returns the string used to quote SQL identifiers. This returns a space " * " if identifier quoting isn't supported. A JDBC-Compliant driver always * uses a double quote character. * * @return the quoting string * @throws SQLException if a database-access error occurs. */ public String getIdentifierQuoteString() throws SQLException { return "\""; } /** * Get a description of the primary key columns that are referenced by a * table's foreign key columns (the primary keys imported by a table). They * are ordered by PKTABLE_CAT, PKTABLE_SCHEM, PKTABLE_NAME, and KEY_SEQ. * <p> * Each primary key column description has the following columns: * <OL> * <LI> <B>PKTABLE_CAT</B> String =>primary key table catalog being * imported (may be null) * <LI> <B>PKTABLE_SCHEM</B> String =>primary key table schema being * imported (may be null) * <LI> <B>PKTABLE_NAME</B> String =>primary key table name being * imported * <LI> <B>PKCOLUMN_NAME</B> String =>primary key column name being * imported * <LI> <B>FKTABLE_CAT</B> String =>foreign key table catalog (may be * null) * <LI> <B>FKTABLE_SCHEM</B> String =>foreign key table schema (may be * null) * <LI> <B>FKTABLE_NAME</B> String =>foreign key table name * <LI> <B>FKCOLUMN_NAME</B> String =>foreign key column name * <LI> <B>KEY_SEQ</B> short =>sequence number within foreign key * <LI> <B>UPDATE_RULE</B> short =>What happens to foreign key when * primary is updated: * <UL> * <LI> importedNoAction - do not allow update of primary key if it has * been imported * <LI> importedKeyCascade - change imported key to agree with primary * key update * <LI> importedKeySetNull - change imported key to NULL if its primary * key has been updated * <LI> importedKeySetDefault - change imported key to default values * if its primary key has been updated * <LI> importedKeyRestrict - same as importedKeyNoAction (for ODBC 2.x * compatibility) * </UL> * * <LI> <B>DELETE_RULE</B> short =>What happens to the foreign key when * primary is deleted. * <UL> * <LI> importedKeyNoAction - do not allow delete of primary key if it * has been imported * <LI> importedKeyCascade - delete rows that import a deleted key * <LI> importedKeySetNull - change imported key to NULL if its primary * key has been deleted * <LI> importedKeyRestrict - same as importedKeyNoAction (for ODBC 2.x * compatibility) * <LI> importedKeySetDefault - change imported key to default if its * primary key has been deleted * </UL> * * <LI> <B>FK_NAME</B> String =>foreign key name (may be null) * <LI> <B>PK_NAME</B> String =>primary key name (may be null) * <LI> <B>DEFERRABILITY</B> short =>can the evaluation of foreign key * constraints be deferred until commit * <UL> * <LI> importedKeyInitiallyDeferred - see SQL92 for definition * <LI> importedKeyInitiallyImmediate - see SQL92 for definition * <LI> importedKeyNotDeferrable - see SQL92 for definition * </UL> * * </OL> * * @param catalog a catalog name; "" retrieves those without a * <code>null</code> means drop catalog name from the selection criteria * @param schema a schema name; "" retrieves those without a schema * @param table a table name * @return ResultSet - each row is a primary key column description * @throws SQLException if a database-access error occurs. * * @see #getExportedKeys */ public java.sql.ResultSet getImportedKeys(String catalog, String schema, String table) throws SQLException { return getCrossReference(null, null, null, catalog, schema, table); } /** * Get a description of a table's indices and statistics. They are ordered * by NON_UNIQUE, TYPE, INDEX_NAME, and ORDINAL_POSITION. <P> * * Each index 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>NON_UNIQUE</B> boolean =>Can index values be non-unique? false * when TYPE is tableIndexStatistic * <LI> <B>INDEX_QUALIFIER</B> String =>index catalog (may be null); null * when TYPE is tableIndexStatistic * <LI> <B>INDEX_NAME</B> String =>index name; null when TYPE is * tableIndexStatistic * <LI> <B>TYPE</B> short =>index type: * <UL> * <LI> tableIndexStatistic - this identifies table statistics that are * returned in conjuction with a table's index descriptions * <LI> tableIndexClustered - this is a clustered index * <LI> tableIndexHashed - this is a hashed index * <LI> tableIndexOther - this is some other style of index * </UL> * * <LI> <B>ORDINAL_POSITION</B> short =>column sequence number within * index; zero when TYPE is tableIndexStatistic * <LI> <B>COLUMN_NAME</B> String =>column name; null when TYPE is * tableIndexStatistic * <LI> <B>ASC_OR_DESC</B> String =>column sort sequence, "A" => * ascending, "D" =>descending, may be null if sort sequence is not * supported; null when TYPE is tableIndexStatistic * <LI> <B>CARDINALITY</B> int =>When TYPE is tableIndexStatistic, then * this is the number of rows in the table; otherwise, it is the number * of unique values in the index. * <LI> <B>PAGES</B> int =>When TYPE is tableIndexStatisic then this is * the number of pages used for the table, otherwise it is the number of * pages used for the current index. * <LI> <B>FILTER_CONDITION</B> String =>Filter condition, if any. (may * be null) * </OL> * * @param catalog a catalog name; "" retrieves those without a * <code>null</code> means drop catalog name from the selection criteria * @param schema a schema name; "" retrieves those without a schema * @param table a table name * @param unique when <code>true</code>, return only indices for unique * values; when <code>false</code>, return indices regardless of * whether unique or not * @param approximate when <code>true</code>, result is allowed to reflect * approximate or out of data values; when <code>false</code>, results * are requested to be accurate * @return ResultSet - each row is an index column description * @throws SQLException if a database-access error occurs. */ public java.sql.ResultSet getIndexInfo(String catalog, String schema, String table, boolean unique, boolean approximate) throws SQLException { String colNames[] = {"TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME", "NON_UNIQUE", "INDEX_QUALIFIER", "INDEX_NAME", "TYPE", "ORDINAL_POSITION", "COLUMN_NAME", "ASC_OR_DESC", "CARDINALITY", "PAGES", "FILTER_CONDITION"}; int colTypes[] = {Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.BIT, Types.VARCHAR, Types.VARCHAR, Types.SMALLINT, Types.SMALLINT, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.VARCHAR}; String query = "sp_statistics ?, ?, ?, ?, ?, ?"; CallableStatement s = connection.prepareCall(syscall(catalog, query)); s.setString(1, table); s.setString(2, schema); s.setString(3, catalog); s.setString(4, "%"); s.setString(5, unique ? "Y" : "N"); s.setString(6, approximate ? "Q" : "E"); JtdsResultSet rs = (JtdsResultSet) s.executeQuery(); int colCnt = rs.getMetaData().getColumnCount(); CachedResultSet rsTmp = new CachedResultSet((JtdsStatement)s, colNames, colTypes);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -