(Study record)
In the Code table class and field class please refer to: http://meijia.blog.51cto.com/8684191/1563874
The relevant parameters can be adjusted by reference to the API.
(Same note format)
1. The method is as follows
Public list<table> Export () {
list<table> tablelist = new arraylist<table> ();
Connection conn = Dbutil.getconnection ();
ResultSet tablers = null; Store metadata
ResultSet Colrs = null;//Storage Table Metadata
try {
DatabaseMetaData Dbmd = Conn.getmetadata ();//Returns the metadata of the database to which this Connection object is connected
Get all Tables
list<string> tablenamelist = new arraylist<string> ();
Tablers = Dbmd.gettables (null, "%", "%", new string[]{"TABLE"}); All tables
while (Tablers.next ()) {
String tableName = tablers.getstring ("table_name");//Table name
Tablenamelist.add (TableName);
}
List<field> FieldList = null;//stores all fields for each table
Table table = null;
for (String name:tablenamelist) {
Table = new Table ();
Get the fields for a table
Colrs = Dbmd.getcolumns (null, "%", name, "%");//field of the current table
Field field = NULL;
FieldList = new arraylist<field> ();
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 that it can be null, and 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;
}
This article is from the "I Will work" blog, please be sure to keep this source http://meijia.blog.51cto.com/8684191/1563879
Oracle reads the table structure in the library