Files
gerrit/check_account.java
2025-12-22 17:12:39 +08:00

85 lines
3.7 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import java.sql.*;
public class check_account {
public static void main(String[] args) {
String dbPath = "/home/renjianbo/gerrit_install/review_site/db/ReviewDB";
try {
Class.forName("org.h2.Driver");
String url = "jdbc:h2:" + dbPath + ";AUTO_SERVER=TRUE";
Connection conn = DriverManager.getConnection(url, "sa", "");
System.out.println("=== 检查账户信息 ===\n");
// 检查 accounts 表H2 数据库表名可能是大写)
System.out.println("1. Accounts 表:");
Statement stmt = conn.createStatement();
// 先尝试查看所有表
ResultSet tables = conn.getMetaData().getTables(null, null, "%", new String[]{"TABLE"});
System.out.println(" 数据库中的表:");
while (tables.next()) {
System.out.println(" - " + tables.getString("TABLE_NAME"));
}
System.out.println();
// 尝试查询账户(使用大写表名)
ResultSet rs = stmt.executeQuery("SELECT ACCOUNT_ID, FULL_NAME, PREFERRED_EMAIL, INACTIVE, REGISTERED_ON FROM ACCOUNTS ORDER BY ACCOUNT_ID");
boolean hasAccounts = false;
while (rs.next()) {
hasAccounts = true;
System.out.println(" Account ID: " + rs.getInt("ACCOUNT_ID"));
System.out.println(" Full Name: " + rs.getString("FULL_NAME"));
System.out.println(" Email: " + rs.getString("PREFERRED_EMAIL"));
System.out.println(" Inactive: " + rs.getInt("INACTIVE"));
System.out.println(" Registered: " + rs.getTimestamp("REGISTERED_ON"));
System.out.println();
}
if (!hasAccounts) {
System.out.println(" (无账户)");
}
// 检查 account_external_ids 表
System.out.println("2. Account External IDs 表:");
rs = stmt.executeQuery("SELECT ACCOUNT_ID, EMAIL_ADDRESS, EXTERNAL_ID FROM ACCOUNT_EXTERNAL_IDS ORDER BY ACCOUNT_ID");
boolean hasExtIds = false;
while (rs.next()) {
hasExtIds = true;
System.out.println(" Account ID: " + rs.getInt("ACCOUNT_ID"));
System.out.println(" Email: " + rs.getString("EMAIL_ADDRESS"));
System.out.println(" External ID: " + rs.getString("EXTERNAL_ID"));
System.out.println();
}
if (!hasExtIds) {
System.out.println(" (无外部ID)");
}
// 检查管理员组
System.out.println("3. 管理员组成员:");
rs = stmt.executeQuery(
"SELECT a.ACCOUNT_ID, a.FULL_NAME " +
"FROM ACCOUNTS a " +
"JOIN ACCOUNT_GROUP_MEMBERS agm ON a.ACCOUNT_ID = agm.ACCOUNT_ID " +
"JOIN ACCOUNT_GROUPS ag ON agm.GROUP_ID = ag.GROUP_ID " +
"WHERE ag.NAME = 'Administrators' " +
"ORDER BY a.ACCOUNT_ID"
);
boolean hasAdmins = false;
while (rs.next()) {
hasAdmins = true;
System.out.println(" Account ID: " + rs.getInt("ACCOUNT_ID") + ", Name: " + rs.getString("FULL_NAME"));
}
if (!hasAdmins) {
System.out.println(" (无管理员)");
}
conn.close();
System.out.println("\n=== 检查完成 ===");
} catch (Exception e) {
System.err.println("错误: " + e.getMessage());
e.printStackTrace();
}
}
}