package com.rongyichuang.region;
|
|
import org.junit.jupiter.api.Test;
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
import java.sql.*;
|
|
@SpringBootTest
|
public class RegionTableTest {
|
|
@Test
|
public void testRegionTableStructure() {
|
String url = "jdbc:mysql://localhost:3306/ryc?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true";
|
String username = "root";
|
String password = "123456";
|
|
try (Connection connection = DriverManager.getConnection(url, username, password)) {
|
System.out.println("=== t_region 表结构 ===");
|
|
// 获取表结构
|
DatabaseMetaData metaData = connection.getMetaData();
|
ResultSet columns = metaData.getColumns(null, null, "t_region", null);
|
|
System.out.println("字段名\t\t类型\t\t\t是否为空\t默认值");
|
System.out.println("----------------------------------------------------");
|
|
while (columns.next()) {
|
String columnName = columns.getString("COLUMN_NAME");
|
String columnType = columns.getString("TYPE_NAME");
|
int columnSize = columns.getInt("COLUMN_SIZE");
|
String isNullable = columns.getString("IS_NULLABLE");
|
String defaultValue = columns.getString("COLUMN_DEF");
|
|
System.out.printf("%-15s %-20s %-10s %s%n",
|
columnName,
|
columnType + "(" + columnSize + ")",
|
isNullable,
|
defaultValue != null ? defaultValue : "NULL"
|
);
|
}
|
|
// 查看现有数据
|
System.out.println("\n=== 现有数据 ===");
|
Statement stmt = connection.createStatement();
|
ResultSet rs = stmt.executeQuery("SELECT * FROM t_region ORDER BY id");
|
|
while (rs.next()) {
|
System.out.printf("ID: %d, Name: %s, PID: %s, Code: %s, Status: %d%n",
|
rs.getLong("id"),
|
rs.getString("name"),
|
rs.getObject("pid"),
|
rs.getString("code"),
|
rs.getInt("status")
|
);
|
}
|
|
} catch (SQLException e) {
|
System.err.println("数据库连接失败: " + e.getMessage());
|
e.printStackTrace();
|
}
|
}
|
}
|