Get the App
SLTechnology News&Howtos  ›  Database  › 

Table structure in Oracle read Library

Shulou Source: shulou.com Published: 2022-06-01 17:20:01 11月01日 Update

(study record)

For Table class and Field class in the code, please refer to: http://meijia.blog.51cto.com/8684191/1563874

You can adjust the relevant parameters by referring to api.

(also pay attention to format)

1. The method is as follows

Public List export () {

List tableList = new ArrayList ()

Connection conn = DBUtil.getConnection ()

ResultSet tableRs = null; / / inventory metadata

ResultSet colRs = null;// stores table metadata

Try {

DatabaseMetaData dbmd = conn.getMetaData (); / / returns the metadata of the database to which this Connection object is connected

/ / get all tables

List tableNameList = new ArrayList ()

TableRs = dbmd.getTables (null, "%", "%", new String [] {"TABLE"}); / / all tables

While (tableRs.next ()) {

String tableName = tableRs.getString ("TABLE_NAME"); / / Table name

TableNameList.add (tableName)

}

List fieldList = null;// stores all fields of each table

Table table = null

For (String name: tableNameList) {

Table = new Table ()

/ / get the fields of the table

ColRs = dbmd.getColumns (null, "%", name, "%"); / / Fields of the current table

Field field = null

FieldList = new ArrayList ()

While (colRs.next ()) {

Field = new Field ()

String columnName = colRs.getString ("COLUMN_NAME"); / / name

String columnType = colRs.getString ("TYPE_NAME"); / / Type

Int datasize = colRs.getInt ("COLUMN_SIZE"); / / Field length

Int digits = colRs.getInt ("DECIMAL_DIGITS")

Int nullable = colRs.getInt ("NULLABLE"); / / return 1 means it can be Null, while 0 means Not Null

Field.setColumnName (columnName)

Field.setTypeName (columnType)

Field.setColumnSize (datasize)

Field.setDecimal_digits (digits)

Field.setNullable (nullable)

FieldList.add (field)

}

Table.setTableName (name)

Table.setField (fieldList)

TableList.add (table)

}

} catch (SQLException ex) {

Logger.getLogger (ExportOracleTable.class.getName ()) .log (Level.SEVERE, null, ex)

} finally {

If (colRs! = null) {

Try {

ColRs.close ()

} catch (SQLException ex) {

Logger.getLogger (ExportOracleTable.class.getName ()) .log (Level.SEVERE, null, ex)

}

}

If (tableRs! = null) {

Try {

TableRs.close ()

} catch (SQLException ex) {

Logger.getLogger (ExportOracleTable.class.getName ()) .log (Level.SEVERE, null, ex)

}

}

If (conn! = null) {

Try {

Conn.close ()

} catch (SQLException ex) {

Logger.getLogger (ExportOracleTable.class.getName ()) .log (Level.SEVERE, null, ex)

}

}

}

Return tableList

}

Tags: Data field database storage code parameter name object method format type length repository reference learning adjustment middle table structure Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple macOS Huawei Docker NVidia