backend/src/test/java/com/rongyichuang/DatabaseConnectionTest.java
New file
@@ -0,0 +1,60 @@
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.util.List;
import java.util.Map;
@SpringBootTest
public class DatabaseConnectionTest {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Test
    public void testDatabaseConnection() {
        try {
            // 检查数据库连接
            String result = jdbcTemplate.queryForObject("SELECT 1", String.class);
            System.out.println("✅ 数据库连接成功: " + result);
            // 检查t_wx_login_record表是否存在
            try {
                String checkTableSql = "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'ryc' AND table_name = 't_wx_login_record'";
                Integer tableExists = jdbcTemplate.queryForObject(checkTableSql, Integer.class);
                if (tableExists != null && tableExists > 0) {
                    System.out.println("✅ t_wx_login_record表存在");
                    // 查看表结构
                    String describeTableSql = "DESCRIBE t_wx_login_record";
                    List<Map<String, Object>> columns = jdbcTemplate.queryForList(describeTableSql);
                    System.out.println("表结构:");
                    for (Map<String, Object> column : columns) {
                        System.out.println("- " + column.get("Field") + ": " + column.get("Type") +
                                         (column.get("Null").equals("NO") ? " NOT NULL" : " NULL") +
                                         (column.get("Default") != null ? " DEFAULT " + column.get("Default") : ""));
                    }
                    // 检查表中是否有数据
                    String countSql = "SELECT COUNT(*) FROM t_wx_login_record";
                    Integer recordCount = jdbcTemplate.queryForObject(countSql, Integer.class);
                    System.out.println("表中记录数: " + recordCount);
                } else {
                    System.out.println("❌ t_wx_login_record表不存在");
                }
            } catch (Exception e) {
                System.out.println("❌ 检查t_wx_login_record表时出错: " + e.getMessage());
                e.printStackTrace();
            }
        } catch (Exception e) {
            System.out.println("❌ 数据库连接失败: " + e.getMessage());
            e.printStackTrace();
        }
    }
}