当前位置: 技术问答>java相关
如何得到字段长度?如: field VCHAR (30)中的 (30)?
来源: 互联网 发布时间:2014-12-26
本文导语: 似乎ResultSetMetaData没有这个方法. | public abstract ResultSet getColumns(String catalog, String schemaPattern, ...
似乎ResultSetMetaData没有这个方法.
|
public abstract ResultSet getColumns(String catalog,
String schemaPattern,
String tableNamePattern,
String columnNamePattern) throws SQLException
Get a description of table columns available in a catalog.
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.
Each column description has the following columns:
TABLE_CAT String => table catalog (may be null)
TABLE_SCHEM String => table schema (may be null)
TABLE_NAME String => table name
COLUMN_NAME String => column name
DATA_TYPE short => SQL type from java.sql.Types
TYPE_NAME String => Data source dependent type name
COLUMN_SIZE int => column size. For char or date types this is the maximum number of characters, for numeric or decimal types this is precision.
BUFFER_LENGTH is not used.
DECIMAL_DIGITS int => the number of fractional digits
NUM_PREC_RADIX int => Radix (typically either 10 or 2)
NULLABLE int => is NULL allowed?
columnNoNulls - might not allow NULL values
columnNullable - definitely allows NULL values
columnNullableUnknown - nullability unknown
REMARKS String => comment describing column (may be null)
COLUMN_DEF String => default value (may be null)
SQL_DATA_TYPE int => unused
SQL_DATETIME_SUB int => unused
CHAR_OCTET_LENGTH int => for char types the maximum number of bytes in the column
ORDINAL_POSITION int => index of column in table (starting at 1)
IS_NULLABLE String => "NO" means column definitely does not allow NULL values; "YES" means the column might allow NULL values. An empty string means nobody knows.
Parameters:
catalog - a catalog name; "" retrieves those without a catalog; null means drop catalog name from the selection criteria
schemaPattern - a schema name pattern; "" retrieves those without a schema
tableNamePattern - a table name pattern
columnNamePattern - a column name pattern
Returns:
ResultSet - each row is a column description
Throws: SQLException
if a database-access error occurs.
String schemaPattern,
String tableNamePattern,
String columnNamePattern) throws SQLException
Get a description of table columns available in a catalog.
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.
Each column description has the following columns:
TABLE_CAT String => table catalog (may be null)
TABLE_SCHEM String => table schema (may be null)
TABLE_NAME String => table name
COLUMN_NAME String => column name
DATA_TYPE short => SQL type from java.sql.Types
TYPE_NAME String => Data source dependent type name
COLUMN_SIZE int => column size. For char or date types this is the maximum number of characters, for numeric or decimal types this is precision.
BUFFER_LENGTH is not used.
DECIMAL_DIGITS int => the number of fractional digits
NUM_PREC_RADIX int => Radix (typically either 10 or 2)
NULLABLE int => is NULL allowed?
columnNoNulls - might not allow NULL values
columnNullable - definitely allows NULL values
columnNullableUnknown - nullability unknown
REMARKS String => comment describing column (may be null)
COLUMN_DEF String => default value (may be null)
SQL_DATA_TYPE int => unused
SQL_DATETIME_SUB int => unused
CHAR_OCTET_LENGTH int => for char types the maximum number of bytes in the column
ORDINAL_POSITION int => index of column in table (starting at 1)
IS_NULLABLE String => "NO" means column definitely does not allow NULL values; "YES" means the column might allow NULL values. An empty string means nobody knows.
Parameters:
catalog - a catalog name; "" retrieves those without a catalog; null means drop catalog name from the selection criteria
schemaPattern - a schema name pattern; "" retrieves those without a schema
tableNamePattern - a table name pattern
columnNamePattern - a column name pattern
Returns:
ResultSet - each row is a column description
Throws: SQLException
if a database-access error occurs.
|
试试:
ResultSet RS = Stmt.executeQuery("select c1,c2 from robber");
java.sql.ResultSetMetaData mm = RS.getMetaData();
System.out.println("The size is:"+mm.getColumnDisplaySize(1)+","+mm.getColumnDisplaySize(2));
ResultSet RS = Stmt.executeQuery("select c1,c2 from robber");
java.sql.ResultSetMetaData mm = RS.getMetaData();
System.out.println("The size is:"+mm.getColumnDisplaySize(1)+","+mm.getColumnDisplaySize(2));