public static void main(String[] args) throws Exception {
String url = "jdbc:mysql:;
String user = "root";
String password = "root";
Class.forName("com.mysql.jdbc.Driver");
Connection connection = DriverManager.getConnection(url, user, password);
DatabaseMetaData metaData = connection.getMetaData();
ResultSet tables = metaData.getTables(null, null, null, null);
List<String> tableList = new ArrayList<String>();
while (tables.next()) {
System.out.println(tables.getString("TABLE_NAME"));
String tableName = tables.getString("TABLE_NAME");
ResultSet columns = metaData.getColumns(null, "%", tableName, "%");
List<String> columnList = new ArrayList<>(20);
while (columns.next()) {
System.out.println(columns.getString("COLUMN_NAME"));
}
}
connection.close();
}
JDBC获取表名以及表相关字段名
最新推荐文章于 2024-01-03 10:06:15 发布