yeg
2026-09-14 39a6b559d0e20df94ce456b8b4303635baa1a35c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import java.sql.*;
public class SchemaDump2 {
  public static void main(String[] a) throws Exception {
    String db = a.length > 0 ? a[0] : "talent_card_test";
    String[] tables = a.length > 1 ? java.util.Arrays.copyOfRange(a, 1, a.length)
        : new String[]{"talent_user","talent_card","merchant_product","merchant","merchant_operator_store","merchant_agreement","merchant_store_consume_rule"};
    String url = "jdbc:mysql://127.0.0.1:8134/" + db + "?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&useSSL=false";
    try (Connection c = DriverManager.getConnection(url, "root", "123456")) {
      for (String t : tables) {
        System.out.println("=== " + t);
        try (PreparedStatement ps = c.prepareStatement(
            "select column_name, column_type, is_nullable, column_default, extra from information_schema.columns where table_schema=database() and table_name=? order by ordinal_position")) {
          ps.setString(1, t);
          try (ResultSet rs = ps.executeQuery()) {
            while (rs.next()) {
              String nn = "NO".equals(rs.getString(3)) ? " NOT NULL" : "";
              String dflt = rs.getString(4) == null ? "" : " def=" + rs.getString(4);
              String extra = rs.getString(5) == null || rs.getString(5).isEmpty() || rs.getString(5).startsWith("DEFAULT_GENERATED") ? "" : " " + rs.getString(5);
              System.out.println("  " + rs.getString(1) + " " + rs.getString(2) + nn + dflt + extra);
            }
          }
        } catch (SQLException e) { System.out.println("  ERR " + e.getMessage()); }
      }
    }
  }
}