简体   繁体   English

尝试使用jdbc元数据获取列的列大小

[英]Trying to get the column size of a column using jdbc metadata

I am trying to recreate a schema for a table using only the metadata from jdbc. 我正在尝试仅使用来自jdbc的元数据为表重新创建架构。

I have it all working except for the column size eg. 我有所有的工作,除了列大小例如。 location VARCHAR(10) 位置VARCHAR(10)

Currently for every column it is printing VARCHAR(2000000000) 当前,它正在为每一列打印VARCHAR(2000000000)

The code: 编码:

ResultSet rs = databaseMetaData.getColumns(null, null, tableName, null);
while(rs.next()) {
  int columnSize = rs.getInt("COLUMN_SIZE");
}

The expected output is the number used when creating the table that is in the schema but it always returns 2000000000. Is there something simple I am missing? 预期的输出是在架构中创建表时使用的数字,但始终返回2000000000。我缺少简单的东西吗?

The tags of your question indicate that you are using SQLite. 您问题的标签表示您正在使用SQLite。

The documentation , chapter 2.2 Affinity Name Examples, states: 文档第2.2章“相似性名称示例”指出:

Note that numeric arguments in parentheses that following the type name (ex: "VARCHAR(255)") are ignored by SQLite - SQLite does not impose any length restrictions (other than the large global SQLITE_MAX_LENGTH limit) on the length of strings, BLOBs or numeric values. 请注意,SQLite会忽略类型名称后面的括号中的数字参数(例如:“ VARCHAR(255)”)-SQLite不会对字符串,BLOB或字符串的长度施加任何长度限制(大的全局SQLITE_MAX_LENGTH限制除外)。数值。

Since SQLite doesn't use the length information, for COLUMN_SIZE it simply returns the maximum size of character based columns. 由于SQLite不使用长度信息,因此对于COLUMN_SIZE,它仅返回基于字符的列的最大大小。

Try using the method 尝试使用方法

databaseMetaData.getColumnDisplaySize(int column)

where the column parameter is the number of column in the table. 其中column参数是表中的列数。 Source: https://docs.oracle.com/javase/7/docs/api/java/sql/ResultSetMetaData.html 来源: https : //docs.oracle.com/javase/7/docs/api/java/sql/ResultSetMetaData.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM