package com.reading.platform.util;

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

public class CheckDatabase {
    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()) {
                // Show tables
                System.out.println("\n=== Tables in database ===");
                ResultSet rs = statement.executeQuery("SHOW TABLES");
                while (rs.next()) {
                    System.out.println("  - " + rs.getString(1));
                }

                // Check class table
                System.out.println("\n=== t_class data ===");
                try {
                    rs = statement.executeQuery("SELECT id, name, grade FROM t_class");
                    while (rs.next()) {
                        System.out.println("  ID: " + rs.getString("id") + ", Name: " + rs.getString("name") + ", Grade: " + rs.getString("grade"));
                    }
                } catch (Exception e) {
                    System.out.println("  Error: " + e.getMessage());
                }

                // Check clazz table (if exists)
                System.out.println("\n=== t_clazz data (if exists) ===");
                try {
                    rs = statement.executeQuery("SELECT id, name, grade FROM t_clazz");
                    while (rs.next()) {
                        System.out.println("  ID: " + rs.getString("id") + ", Name: " + rs.getString("name") + ", Grade: " + rs.getString("grade"));
                    }
                } catch (Exception e) {
                    System.out.println("  Table t_clazz not found or empty");
                }
            }
        }
    }
}
