读取数据库中的所有的表名
private Set<String> getTableNameByCon(Connection con) { Set<String> set = new HashSet<String>(); try { DatabaseMetaData meta = con.getMetaData(); ResultSet rs = meta.getTables(null, null, null, new String[] { "TABLE" }); while (rs.next()) { set.add(rs.getString(3)); } con.close(); } catch (Exception e) { try { con.close(); } catch (SQLException e1) { e1.printStackTrace(); } e.printStackTrace(); } return set; }
读取表介绍
private void getTableNotes(Connection con){ try { DatabaseMetaData dbmd=con.getMetaData(); ResultSet resultSet = dbmd.getTables(null, "%", "%", new String[] { "TABLE" }); while (resultSet.next()) { String tableName=resultSet.getString("TABLE_NAME"); String remarkes = resultSet.getString("REMARKS"); System.out.println(tableName+"="+remarkes); } } catch (Exception e) { e.printStackTrace(); } }
其他属性等
String tableName = tableSet.getString("TABLE_NAME"); String tableComment = tableSet.getString("REMARKS"); String columnName = columnSet.getString("COLUMN_NAME"); String columnComment = columnSet.getString("REMARKS"); String sqlType = columnSet.getString("DATA_TYPE");
时间: 2024-10-09 09:10:53