@Override public void columnsForTables(Table table, DatabaseMetaData dbmd) { try { rs = dbmd.getColumns(null, "%", table.getName(), null); ResultSet priamryKeyRs = dbmd.getPrimaryKeys(null, null, table.getName()); String priamryKey = null; while (priamryKeyRs.next()) { priamryKey = priamryKeyRs.getString("COLUMN_NAME"); } while (rs.next()) { Column column = new Column(); String name = rs.getString("COLUMN_NAME"); column.setName(name); column.setType(rs.getString("TYPE_NAME")); int columnSize = rs.getInt("COLUMN_SIZE"); int nullable = rs.getInt("nullable"); column.setNullable(nullable == 1); column.setDataSize(columnSize); if (column.getName().equals(priamryKey)) { column.setPrimaryKey(true); } table.addColumn(column); } } catch (SQLException e) { e.printStackTrace(); } }
@Override public void commentForTables(Table table, Connection connection) { try { String sql = "SHOW TABLE STATUS "; pstmt = connection.prepareStatement(sql); rs = pstmt.executeQuery(); table.setComment(table.getName()); while (rs.next()) { if (table.getName().equals(rs.getString("name"))) { String comment = rs.getString("comment"); if (StringKit.notBlank(comment)) { table.setComment(rs.getString("comment")); } } } } catch (SQLException e) { e.printStackTrace(); } }
@Override public void commentForTables(Table table, Connection connection) { try { String sql = "select table_name,comments from user_tab_comments where table_name=?"; pstmt = connection.prepareStatement(sql); rs = pstmt.executeQuery(); table.setComment(table.getName()); while (rs.next()) { if (table.getName().equals(rs.getString("table_name"))) { String comment = rs.getString("comments"); if (StringKit.notBlank(comment)) { table.setComment(comment); } } } } catch (SQLException e) { e.printStackTrace(); } }
@Override public void commentForColumns(Table table, Connection connection) { try { String sql = "show full columns from" + " " + table.getName(); pstmt = connection.prepareStatement(sql); rs = pstmt.executeQuery(); Map<String, String> val = new HashMap<String, String>(); while (rs.next()) { val.put(rs.getString("Field"), rs.getString("COMMENT")); } List<Column> columns = table.getColumns(); for (Column column : columns) { column.setComment(column.getName()); String comment = val.get(column.getName()); if (StringKit.notBlank(comment)) { column.setComment(comment); } } } catch (SQLException e) { e.printStackTrace(); } }
@Override public void commentForColumns(Table table, Connection connection) { try { String sql = "select * from user_col_comments where TABLE_NAME = ?"; pstmt = connection.prepareStatement(sql); pstmt.setString(1, table.getName()); rs = pstmt.executeQuery(); List<Column> columns = table.getColumns(); for (Column column : columns) { column.setComment(column.getName()); while (rs.next()) { if (column.getName().equals(rs.getString("COLUMN_NAME"))) { String comment = rs.getString("COMMENTS"); if (StringKit.notBlank(comment)) { column.setComment(comment); continue; } } } } } catch (SQLException e) { e.printStackTrace(); } }