我需要在表格中询问我的列 jdbc 类型,今天我循环抛出我的列,然后询问它的类型,请参见下面的代码:
public int getColumnDataTypeFromDB(String columnName) {
int datatype = 0;
ResultSet columns = null;
try {
String schema =
getMetaDataCatalogName() != null
? getMetaDataCatalogName()
: getMetaDataSchemaName();
if (TableManagerFactory.isCatalogBasedDatabase()) {
columns =
getMetaData().getColumns(
schema,
null,
tableName,
columnName);
} else {
columns =
getMetaData().getColumns(
null,
schema,
tableName,
columnName);
}
// columns =
// getMetaData().getColumns(getMetaDataCatalogName(), getMetaDataSchemaName(), tableName, columnName);
if (columns.next()) {
datatype = columns.getInt("DATA_TYPE");
}
} catch (SQLException ex) {
Log.error(
this,
"Error while getting columns information: " + ex.getMessage(),
ex);
//return false;
} catch (DDLCreationException ex) {
Log.error(this, ex.getMessage());
} finally {
try {
if (columns != null) {
columns.close();
}
} catch (SQLException ex) {
Log.error(this, ex.getLocalizedMessage());
}
}
return datatype;
}
我可以同时获取此类表中的所有列元数据吗?如果是,我该怎么做?