如何得到字段长度?如: field VCHAR (30)中的 (30)?

aoao 2001-02-22 10:17:00
似乎ResultSetMetaData没有这个方法.
...全文
127 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
skyyoung 2001-02-22
  • 打赏
  • 举报
回复
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.
虎叔 2001-02-22
  • 打赏
  • 举报
回复
试试:
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));
happyno9 2001-02-22
  • 打赏
  • 举报
回复
如果你是用adodb访问的话,我知道可以得到这个值
随风来去 2001-02-22
  • 打赏
  • 举报
回复
关注
howlet 2001-02-22
  • 打赏
  • 举报
回复
ResultSetMetaData rsm = ResultSet.getMetaData();
int length = rsm getColumnDisplaySize(column);
//column - the first column is 1, the second is 2, ...

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧