lrj
2 天以前 c61d4fe27c97d2ecc907756aa571a4ef14a7b9b6
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package com.rongyichuang;
 
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.jdbc.core.JdbcTemplate;
 
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
 
@SpringBootTest
public class ActivityTableSchemaTest {
 
    @Autowired
    private JdbcTemplate jdbcTemplate;
 
    @Test
    public void testActivityTableSchema() {
        try {
            DatabaseMetaData metaData = jdbcTemplate.getDataSource().getConnection().getMetaData();
            
            System.out.println("=== t_activity 表结构 ===");
            ResultSet columns = metaData.getColumns(null, null, "t_activity", null);
            
            while (columns.next()) {
                String columnName = columns.getString("COLUMN_NAME");
                String dataType = columns.getString("TYPE_NAME");
                int columnSize = columns.getInt("COLUMN_SIZE");
                String isNullable = columns.getString("IS_NULLABLE");
                String columnDefault = columns.getString("COLUMN_DEF");
                String remarks = columns.getString("REMARKS");
                
                System.out.printf("列名: %s, 类型: %s(%d), 可空: %s, 默认值: %s, 备注: %s%n", 
                    columnName, dataType, columnSize, isNullable, columnDefault, remarks);
            }
            
            columns.close();
            
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}