package com.reading.platform.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;

public class CheckClazzTable {
    public static void main(String[] args) throws Exception {
        String url = "jdbc:mysql://8.148.151.56:3306/reading_platform?useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true";
        String user = "root";
        String password = "reading_platform_pwd";

        try (Connection conn = DriverManager.getConnection(url, user, password)) {
            System.out.println("Connected to database successfully");

            try (Statement statement = conn.createStatement()) {
                // Check t_clazz structure
                System.out.println("\n=== t_clazz table structure ===");
                ResultSet rs = statement.executeQuery("DESCRIBE t_clazz");
                while (rs.next()) {
                    System.out.println("  " + rs.getString("Field") + " - " + rs.getString("Type"));
                }

                // Check existing data
                System.out.println("\n=== t_clazz existing data ===");
                rs = statement.executeQuery("SELECT * FROM t_clazz");
                ResultSetMetaData meta = rs.getMetaData();
                while (rs.next()) {
                    StringBuilder sb = new StringBuilder("  ");
                    for (int i = 1; i <= meta.getColumnCount(); i++) {
                        sb.append(meta.getColumnName(i)).append("=").append(rs.getString(i)).append(", ");
                    }
                    System.out.println(sb.toString());
                }
            }
        }
    }
}
