📄 jdbcresultsetmetadata.java
字号:
return columnMetaData[--column].schemaName; } /** * <!-- start generic documentation --> * Get the designated column's number of decimal digits. <p> * <!-- end generic documentation --> * * <!-- start Release-specific documentation --> * <div class="ReleaseSpecificDocumentation"> * <h3>HSQLDB-Specific Information:</h3> <p> * * Starting with 1.8.0, HSQLDB reports the the declared * length or precision specifiers for table columns (if they are defined, * which up to 1.7.2 is not a requirement in DDL), as these values may or * may not be enforced, depending on the value of the database * property: <p> * * <pre> * sql.enforce_strict_size * </pre> * * Because the property may change from one instantiation of a Database * to the next and because, when set true, is not applied to existing * values in table columns (only to new values introduced by following * inserts and updates), the length and/or precision specifiers for table * columns still do not neccessarily accurately reflect true constraints * upon the contents of the columns. This situation may or may not change * in a future release. <p> * * </div> * <!-- end release-specific documentation --> * * @param column the first column is 1, the second is 2, ... * @return precision * @exception SQLException if a database access error occurs */ public int getPrecision(int column) throws SQLException { checkColumn(column); return columnMetaData[--column].precision; } /** * <!-- start generic documentation --> * Gets the designated column's number of digits to right of the * decimal point. <p> * <!-- end generic documentation --> * * <!-- start Release-specific documentation --> * <div class="ReleaseSpecificDocumentation"> * <h3>HSQLDB-Specific Information:</h3> <p> * * Starting with 1.8.0, HSQLDB reports the declared * scale for table columns depending on the value of the database * property: <p> * * <pre> * sql.enforce_strict_size * </pre> * * </div> * <!-- end release-specific documentation --> * * @param column the first column is 1, the second is 2, ... * @return scale * @exception SQLException if a database access error occurs */ public int getScale(int column) throws SQLException { checkColumn(column); return columnMetaData[--column].scale; } /** * <!-- start generic documentation --> * Gets the designated column's table name. <p> * <!-- end generic documentation --> * @param column the first column is 1, the second is 2, ... * @return table name or "" if not applicable * @exception SQLException if a database access error occurs */ public String getTableName(int column) throws SQLException { checkColumn(column); return columnMetaData[--column].tableName; } /** * <!-- start generic documentation --> * Gets the designated column's table's catalog name. <p> * <!-- end generic documentation --> * * <!-- start Release-specific documentation --> * <div class="ReleaseSpecificDocumentation"> * <h3>HSQLDB-Specific Information:</h3> <p> * * Up to and including 1.7.1, HSQLDB did not support the notion of * catalog and this method always returned "". <p> * * Starting with 1.7.2, HSQLDB supports catalog reporting only as an * optional, experimental feature that is disabled by default. Enabling * this feature requires setting the database property * "hsqldb.catalogs=true". When enabled, the catalog name for table columns * is reported as the name by which the hosting Database knows itself. <p> * * HSQLDB does not yet support any use of catalog qualification in * DLL or DML. This fact is accurately indicated in the corresponding * DatabaseMetaData.supportsXXX() method return values. <p> * * Regardless, reporting is done only in system table content and is * not yet carried over to ResultSetMetaData. <p> * * For greater detail, see discussion at: * {@link jdbcDatabaseMetaData}. <p> * * </div> * <!-- end release-specific documentation --> * * @param column the first column is 1, the second is 2, ... * @return the name of the catalog for the table in which the given column * appears or "" if not applicable * @exception SQLException if a database access error occurs */ public String getCatalogName(int column) throws SQLException { checkColumn(column); return columnMetaData[--column].catalogName; } /** * <!-- start generic documentation --> * Retrieves the designated column's SQL type. <p> * <!-- end generic documentation --> * * <!-- start Release-specific documentation --> * <div class="ReleaseSpecificDocumentation"> * <h3>HSQLDB-Specific Information:</h3> <p> * * This reports the SQL type of the column. HSQLDB can return Objects in * any Java integral type wider than <code>Integer</code> for an SQL * integral type.<p> * * </div> * <!-- end release-specific documentation --> * * * @param column the first column is 1, the second is 2, ... * @return SQL type from java.sql.Types * @exception SQLException if a database access error occurs * @see java.sql.Types */ public int getColumnType(int column) throws SQLException { checkColumn(column); int type = columnMetaData[--column].columnType; return type == Types.VARCHAR_IGNORECASE ? Types.VARCHAR : type; } /** * <!-- start generic documentation --> * Retrieves the designated column's database-specific type name. <p> * <!-- end generic documentation --> * * @param column the first column is 1, the second is 2, ... * @return type name used by the database. If the column type is * a user-defined type, then a fully-qualified type name is returned. * @exception SQLException if a database access error occurs */ public String getColumnTypeName(int column) throws SQLException { checkColumn(column); return columnMetaData[--column].columnTypeName; } /** * <!-- start generic documentation --> * Indicates whether the designated column is definitely not writable.<p> * <!-- end generic documentation --> * * <!-- start Release-specific documentation --> * <div class="ReleaseSpecificDocumentation"> * <h3>HSQLDB-Specific Information:</h3> <p> * * Up to and including 1.7.1, HSQLDB did not report this value accurately. * <p> * * Starting with HSQLDB 1.7.2, this feature is better supported. <p> * * For result set columns that do not directly * represent table column values (i.e. are calculated), true is reported. * Otherwise, the read only status of the table and the database are used * in the calculation, but not the read-only status of the session. <p> * * </div> * <!-- end release-specific documentation --> * * @param column the first column is 1, the second is 2, ... * @return <code>true</code> if so; <code>false</code> otherwise * @exception SQLException if a database access error occurs */ public boolean isReadOnly(int column) throws SQLException { checkColumn(column); return columnMetaData[--column].isReadOnly; } /** * <!-- start generic documentation --> * Indicates whether it is possible for a write on the designated * column to succeed. <p> * <!-- end generic documentation --> * * <!-- start Release-specific documentation --> * <div class="ReleaseSpecificDocumentation"> * <h3>HSQLDB-Specific Information:</h3> <p> * * Up to and including 1.7.1, HSQLDB did not report this value accurately. * <p> * * Starting with HSQLDB 1.7.2, this feature is better supported. <p> * * In essense, the negation of isReadOnly() is reported. <p> * * </div> * <!-- end release-specific documentation --> * * @param column the first column is 1, the second is 2, ... * @return <code>true</code> if so; <code>false</code> otherwise * @exception SQLException if a database access error occurs */ public boolean isWritable(int column) throws SQLException { checkColumn(column); return columnMetaData[--column].isWritable; } /** * <!-- start generic documentation --> * Indicates whether a write on the designated column will definitely * succeed. <p> * <!-- end generic documentation --> * * <!-- start Release-specific documentation --> * <div class="ReleaseSpecificDocumentation"> * <h3>HSQLDB-Specific Information:</h3> <p> * * HSQLDB 1.7.1 did not report this value accurately. <p> * * Starting with HSQLDB 1.7.2, this method always returns false. The * reason for this is that it is generally either very complex or * simply impossible to calculate deterministically true for table columns * under all concievable conditions. The value is of dubious usefulness, except * perhaps if there were support for updateable result sets using * "SELECT ... FOR UPDATE" style locking. However, this is not anticipated to * occur any time in the 1.7.x release series. <p> * * </div> * <!-- end release-specific documentation --> * * @param column the first column is 1, the second is 2, ... * @return <code>true</code> if so; <code>false</code> otherwise * @exception SQLException if a database access error occurs */ public boolean isDefinitelyWritable(int column) throws SQLException { checkColumn(column);// NOTE:// boucherb@users - 20020329// currently, we can't tell _for sure_ that this is true without a// great deal more work (and even then, not necessarily deterministically),// plus it is of dubious usefulness to know this is true _for sure_ anyway.// It's not like one can do an insert or update without a try-catch block// using JDBC, even if one knows that a column is definitely writable. And// the catch will always let us know if there is a failure and why. Also,// it is typically completely useless to know that, although it is _possible_// that a write may succeed (as indicated by a true value of isWritable()),// it also might fail (as indicated by a false returned here). // as of 1.7.2, always false return columnMetaData[--column].isDefinitelyWritable; } //--------------------------JDBC 2.0----------------------------------- /** * <!-- start generic documentation --> * Returns the fully-qualified name of the Java class whose instances * are manufactured if the method <code>ResultSet.getObject</code> * is called to retrieve a value from the column. * <code>ResultSet.getObject</code> may return a subclass of the class * returned by this method. <p> * <!-- end generic documentation --> * * <!-- start Release-specific documentation --> * <div class="ReleaseSpecificDocumentation"> * <h3>HSQLDB-Specific Information:</h3> <p> * * HSQLDB 1.7.1 did not support this feature; calling this method * always caused an <code>SQLException</code> to be thrown, * stating that the function was not supported. <p> * * </div> * <!-- end release-specific documentation --> * * @param column the first column is 1, the second is 2, ... * @return the fully-qualified name of the class in the Java programming * language that would be used by the method * <code>ResultSet.getObject</code> to retrieve the value in the * specified column. This is the class name used for custom mapping. * @exception SQLException if a database access error occurs * @since JDK 1.2 (JDK 1.1.x developers: read the new overview for * jdbcResultSet) */ public String getColumnClassName(int column) throws SQLException { checkColumn(column); return columnMetaData[--column].columnClassName; } public String toString() { StringBuffer sb = new StringBuffer(); sb.append(super.toString()); if (columnCount == 0) { sb.append("[columnCount=0]"); return sb.toString(); } sb.append('['); for (int i = 0; i < columnCount; i++) { sb.append('\n'); sb.append(" column_"); sb.append(i + 1); sb.append('='); sb.append(columnMetaData[i]); if (i + 1 < columnCount) { sb.append(','); sb.append(' '); } } sb.append('\n'); sb.append(']'); return sb.toString(); }// ------------------------- Internal Implementation --------------------------- /** * Performs an internal check for column index validity. <p> * * @param column index of column to check * @throws SQLException when this object's parent ResultSet has * no such column */ private void checkColumn(int column) throws SQLException { if (column < 1 || column > columnCount) { throw Util.sqlException(Trace.COLUMN_NOT_FOUND, String.valueOf(column)); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -