对比新文件 |
| | |
| | | package com.lunhan.xxx.host; |
| | | |
| | | import com.lunhan.xxx.common.util.StringUtil; |
| | | |
| | | import java.sql.Connection; |
| | | import java.sql.DriverManager; |
| | | import java.sql.SQLException; |
| | | import java.util.List; |
| | | |
| | | public class DataBaseExportTest { |
| | | public static void main(String[] args) { |
| | | String dbName = "water_trade_center"; |
| | | |
| | | Connection CONN; |
| | | //获得连接 |
| | | try { |
| | | CONN = DriverManager.getConnection("jdbc:postgresql://113.250.189.120:57654/" + dbName, "lunhan", "lunhan.20240330"); |
| | | } catch (SQLException e) { |
| | | System.out.println(e.toString()); |
| | | return; |
| | | } |
| | | |
| | | List<String> listSql = GenCodeGauss.export(CONN, dbName); |
| | | String sql = StringUtil.join(listSql, "\n\n"); |
| | | |
| | | System.out.println(sql); |
| | | } |
| | | } |
| | |
| | | Map<String, String> mapColumnDesc = new HashMap<>(); |
| | | int idx = 0; |
| | | |
| | | list.add("-- \"" + tableName + "\" - \"" + tableDesc + "\"\nDROP TABLE IF EXISTS \"public\".\"" + tableName + "\";\n"); |
| | | list.add("-- " + tableName + " - " + tableDesc + "\nDROP TABLE IF EXISTS \"public\".\"" + tableName + "\";\n"); |
| | | |
| | | // 遍历列,构建sql |
| | | for (Map<String, Object> column : listColumn) { |
| | |
| | | case "char": |
| | | case "varchar": |
| | | case "nvarchar": |
| | | if (Objects.nonNull(column.get("length"))) { |
| | | String length = column.get("length").toString(); |
| | | sql += "(" + length + ")"; |
| | | } |
| | | if ("1".equals(isNullable)) { |
| | | sql += " NULL DEFAULT NULL"; |
| | | } else { |
| | |
| | | } |
| | | return listTable; |
| | | } |
| | | public static List<String> export(Connection connect, String dbSchema) { |
| | | return GenCodeGauss.export(connect, dbSchema, Boolean.TRUE, Boolean.TRUE); |
| | | } |
| | | } |