From f063c5056d80336ff211deb5bd274e2fe9268014 Mon Sep 17 00:00:00 2001 From: heshunme Date: Sun, 14 Jul 2024 13:19:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=AF=B9UserInfo=E7=9A=84?= =?UTF-8?q?=E6=94=AF=E6=8C=81=EF=BC=8C=E4=BF=AE=E6=94=B9=E4=BA=86users?= =?UTF-8?q?=E8=A1=A8=EF=BC=8CfakeUser=EF=BC=8C=E7=94=A8=E4=BA=8E=E6=94=AF?= =?UTF-8?q?=E6=8C=81index=E7=9A=84=E6=B8=B2=E6=9F=93=E7=9A=84getUserInfo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/web_assignment/DatabaseService.java | 59 ++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/web/web_assignment/DatabaseService.java b/src/main/java/com/web/web_assignment/DatabaseService.java index af18bda..2585ee1 100644 --- a/src/main/java/com/web/web_assignment/DatabaseService.java +++ b/src/main/java/com/web/web_assignment/DatabaseService.java @@ -64,7 +64,14 @@ public class DatabaseService { String createUsersTable = "CREATE TABLE users (" + "id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, " + "username VARCHAR(255) UNIQUE, " + - "password VARCHAR(255))"; + "name VARCHAR(255), " + + "password VARCHAR(255), " + + "introduction CLOB, " + + "interests CLOB, " + + "experiences CLOB, " + + "skills CLOB, " + + "careerGoals CLOB, " + + "projects CLOB)"; String createProjectsTable = "CREATE TABLE projects (" + "id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, " + @@ -141,6 +148,46 @@ public class DatabaseService { } } + + // 更新用户信息的方法 + public void updateUserInfo(String username, UserInfo userInfo) throws SQLException { + String sql = "UPDATE users SET introduction = ?, interests = ?, experiences = ?, skills = ?, careerGoals = ?, name = ? WHERE username = ?"; + try (Connection conn = getConnection(); + PreparedStatement stmt = conn.prepareStatement(sql)) { + + stmt.setString(1, userInfo.getIntroduction()); + stmt.setString(2, userInfo.getInterests()); + stmt.setString(3, userInfo.getExperiences()); + stmt.setString(4, userInfo.getSkills()); + stmt.setString(5, userInfo.getCareerGoals()); + stmt.setString(6, userInfo.getName()); + stmt.setString(7, username); + + stmt.executeUpdate(); + } + } + + public UserInfo getUserInfo(String username) throws SQLException { + String sql = "SELECT * FROM users WHERE username = ?"; + try (Connection conn = getConnection(); + PreparedStatement stmt = conn.prepareStatement(sql)) { + stmt.setString(1, username); + ResultSet rs = stmt.executeQuery(); + if (rs.next()) { + return new UserInfo( + rs.getString("username"), + rs.getString("introduction"), + rs.getString("interests"), + rs.getString("experiences"), + rs.getString("skills"), + rs.getString("careerGoals")); + } + } catch (SQLException e) { + e.printStackTrace(); + } + return null; + } + public void saveProjects(String username, List projects) throws SQLException { try (Connection conn = getConnection()) { for (Project project : projects) { @@ -189,6 +236,16 @@ public class DatabaseService { public void loadFakeUsers() throws SQLException { registerUser("admin", "admin"); registerUser("user", "user"); + UserInfo userInfo = new UserInfo( + "Ryan Goodwill", + "Hello! I'm Ryan Goodwill, a passionate programmer. I'm interested in various AI models and their applications, Raspberry Pi projects, playing the piano, playing tennis, and cycling.", + "Pascal, C++, Python, Java, Django, Raspberry Pi projects, AI model experimentation, sensor integration, control systems, web development, remote hardware control, video streaming, communication protocols.", + "Elementary school programming with Pascal -> Learned C++ and Python -> University projects in Java (Cloud Factory Management System, Android Weather Forecast App) -> Raspberry Pi projects (infrared communication protocol, plant care box with sensors, control webpage) -> Deployed and tested Large Language Models and AI voice synthesis -> Ongoing project: video downloading, OCR, ASR, SVG conversion, LLM querying.", + "Python, C++, Java, Pascal, Django, Raspberry Pi, AI models, Sensors, Control Systems, Web Development, Remote Hardware Control, Video Streaming, Communication Protocol Development.", + "To work in an internet company for a few years before starting my own business." + ); + updateUserInfo("admin", userInfo); + updateUserInfo("user", userInfo); } public void loadAndSaveFakeProjects() throws SQLException {