SpiderDB數(shù)據(jù)庫結(jié)構(gòu)扒取工具
SpiderDB 是一個輕量級的數(shù)據(jù)庫結(jié)構(gòu)扒取工具,使用 Java 開發(fā)。它是一個簡單的類庫可根據(jù)數(shù)據(jù)庫的表結(jié)構(gòu)來生成 POJO 對象,使用簡單,支持各種不同的數(shù)據(jù)庫系統(tǒng)。
示例代碼:
DBCrawler dbCrawler = new DBCrawler(connection, ConfigEnum.MAXIMUM);
DataBase dataBase = dbCrawler.getDatabase();
System.out.println("productName :" + dataBase.getProductName() + " version:" + dataBase.getProductVersion());
//Return Schemas
SchemaSet schemaSet = dataBase.getSchemaSet();
Set<Schema> schemas = schemaSet.getSchemas();
//Iterate to Fetch the schema information and Tables
for(Schema schema : schemas)
{
System.out.println("SchemaName :" + schema.getSchamaName());
TableSet tableSet = schema.getTableSet();
Set<Table> tables = tableSet.getTables();
//Iterate to fetch the tables
for(Table table : tables)
{
System.out.println("tableName :" + table.getTableName());
PrimaryKey primaryKey = table.getPrimaryKey();
System.out.println("pk_Name:"+primaryKey.getPkName() + " PrimaryKey Columns:" + primaryKey.getColumns());
ColumnSet columnSet = table.getColumnSet();
System.out.println("Table Columns:"+ columnSet.getColumns());
Set<ForeignKey> foreignKeys = table.getForeignKeys();
System.out.println("foreignKeys:"+foreignKeys);
}
}
