58 lines
2.5 KiB
Java
58 lines
2.5 KiB
Java
package scripts.qa;
|
|
|
|
import java.io.File;
|
|
import java.nio.file.Files;
|
|
import java.sql.*;
|
|
|
|
public class CheckRound3bDatabase {
|
|
public static void main(String[] args) throws Exception {
|
|
Class.forName("com.kingbase8.Driver");
|
|
|
|
// Read password safely from ~/.railwaysystem-qa.env
|
|
File envFile = new File(System.getProperty("user.home"), ".railwaysystem-qa.env");
|
|
String pass = "";
|
|
if (envFile.exists()) {
|
|
for (String line : Files.readAllLines(envFile.toPath())) {
|
|
line = line.trim();
|
|
if (line.startsWith("QA_DB_PASSWORD=")) {
|
|
pass = line.substring("QA_DB_PASSWORD=".length()).trim();
|
|
if (pass.startsWith("\"") && pass.endsWith("\"")) {
|
|
pass = pass.substring(1, pass.length() - 1);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (pass.isEmpty()) {
|
|
throw new IllegalStateException("QA_DB_PASSWORD is required and must be configured in ~/.railwaysystem-qa.env");
|
|
}
|
|
|
|
String dbUrl = "jdbc:kingbase8://192.168.139.218:4321/railwaysystem_integrated_qa_20260916?useUnicode=true&characterEncoding=utf8";
|
|
try (Connection conn = DriverManager.getConnection(dbUrl, "kingbase", pass)) {
|
|
try (Statement st = conn.createStatement()) {
|
|
try (ResultSet rs = st.executeQuery("SELECT current_database(), current_user")) {
|
|
if (rs.next()) {
|
|
System.out.println("CURRENT_DATABASE=" + rs.getString(1));
|
|
System.out.println("CURRENT_USER=" + rs.getString(2));
|
|
}
|
|
}
|
|
|
|
String[] tables = new String[]{
|
|
"train_class_plan", "train_teacher", "train_student", "train_course",
|
|
"train_classroom_info", "train_training_site", "train_dormitory_info",
|
|
"train_lesson", "train_enrollment", "train_accommodation", "train_student_checkin",
|
|
"train_dorm_auth", "train_external_operation", "train_student_portrait", "train_study_duration",
|
|
"sys_user", "sys_role"
|
|
};
|
|
|
|
for (String t : tables) {
|
|
try (ResultSet rs = st.executeQuery("SELECT count(*) FROM public." + t)) {
|
|
if (rs.next()) {
|
|
System.out.println("TABLE_" + t.toUpperCase() + "=" + rs.getInt(1));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|