1,获取database所有table名:
复制代码 代码示例:
DatabaseMetaData md = conn.getMetaData();
ResultSet rs = md.getTables(null, null, "%", null);
while (rs.next()) {
System.out.println(rs.getString(3));
}
原理:
Column 3 is the TABLE_NAME (see documentation of getTables).
2、获取某table的所有字段名:
复制代码 代码示例:
DatabaseMetaData meta = conn.getMetaData();
ResultSet resultSet = meta.getColumns(databaseName, null, tableName, "%");
while (resultSet.next()) {
System.out.println(esultSet.getString(4));
}