|
@@ -1,5 +1,6 @@
|
|
|
package org.snowchen.GreatSonServer.programinit;
|
|
|
|
|
|
+import java.sql.*;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Scanner;
|
|
|
import java.util.UUID;
|
|
@@ -38,6 +39,7 @@ public class UserInit {
|
|
|
UserData[4] = this.user_register_time;
|
|
|
System.out.println("用户名:" + this.user_name + "\n密码:" + this.user_password + "\nuuid:" + this.uuid + "\n注册时间:" + this.user_register_time);
|
|
|
System.out.println("UserData: " + Arrays.toString(UserData));
|
|
|
+ insertUserData(UserData);
|
|
|
}
|
|
|
|
|
|
// 提供一个公共方法来获取UserData数组
|
|
@@ -45,6 +47,32 @@ public class UserInit {
|
|
|
return UserData;
|
|
|
}
|
|
|
|
|
|
+ public void insertUserData(String[] UserData) {
|
|
|
+ String url = "jdbc:sqlite:test.db"; // SQLite数据库URL
|
|
|
+ String sql = "INSERT INTO user_data (user_name, user_password, user_uuid, user_permission_level, user_register_time) VALUES (?, ?, ?, ?, ?)";
|
|
|
+
|
|
|
+ try (Connection conn = DriverManager.getConnection(url);
|
|
|
+ PreparedStatement pstmt = conn.prepareStatement(sql)) {
|
|
|
+
|
|
|
+ pstmt.setString(1, UserData[0]);
|
|
|
+ pstmt.setString(2, UserData[1]);
|
|
|
+ pstmt.setString(3, UserData[2]);
|
|
|
+ pstmt.setInt(4, Integer.parseInt(UserData[3])); // 假设user_permission_level是整数
|
|
|
+ pstmt.setString(5, UserData[4]); // 假设user_register_time是字符串形式的纳秒时间戳
|
|
|
+
|
|
|
+ int affectedRows = pstmt.executeUpdate();
|
|
|
+ if (affectedRows > 0) {
|
|
|
+ System.out.println("用户数据插入成功");
|
|
|
+ } else {
|
|
|
+ System.out.println("用户数据插入失败");
|
|
|
+ }
|
|
|
+ } catch (SQLException e) {
|
|
|
+ System.err.println("数据库错误: " + e.getMessage());
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.err.println("错误: " + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private static final String PWD_REGEX = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d).{8,}$";
|
|
|
|
|
|
/**
|