通常对于用户定义的类型,我可以简单地执行以下操作(简化但实用的示例):
//Create table
create type myType1 as object( a char(2), b char(2) );
create type myTable1 as table of myType1;
//Java code
ArrayDescriptor des = ArrayDescriptor.createDescriptor( "MYTABLE1", con);
StructDescriptor sDes = StructDescriptor.createDescriptor( des.getBaseName(), con);
//Populte the metadata
String columnName = sDes.getColumnName(0);
int oracleType = sDes.getColumnType(0);
int maxSize = sDes.getColumnDisplaySize(0);
boolean isNullable = sDes.isNullable(0)>0;
除了现在我有一个用原始类型而不是结构定义的表,而且我似乎无法访问元数据。我当前的代码是:
//Create table
create or replace type myTable2 as table of char(2);
//Java code
ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor( "MYTABLE2", con);
//This next line would throw an exception, as CHAR type is not a structure
//StructDescriptor sDes = StructDescriptor.createDescriptor( des.getBaseName(), con);
//Populte the metadata
int oracleType = descriptor.getBaseType(); // This Works
String columnName = "COLUMN_VALUE"; // This Works (I think)
int maxSize = ???? // How do I access the '2'?
boolean isNullable = ???? // How do I access isNullable?
最佳答案
希望我没听错。如果您可以获得列信息,您可以尝试以下代码。
DatabaseMetaData databaseMetaData = connection.getMetaData();
ResultSet columns = databaseMetaData.getColumns(null,null, tableName, null);
while(columns.next())
{
String columnName = columns.getString("COLUMN_NAME");
String datatype = columns.getString("DATA_TYPE");
String columnsize = columns.getString("COLUMN_SIZE");
String decimaldigits = columns.getString("DECIMAL_DIGITS");
String isNullable = columns.getString("IS_NULLABLE");
String is_autoIncrment = columns.getString("IS_AUTOINCREMENT");
}
关于java - 是否可以从 Java 代码获取嵌套表/数组的元数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51790295/