{"id":271,"date":"2024-08-22T16:23:14","date_gmt":"2024-08-22T08:23:14","guid":{"rendered":"https:\/\/note.ui11.cc\/?p=271"},"modified":"2024-08-22T16:23:15","modified_gmt":"2024-08-22T08:23:15","slug":"%e6%95%b0%e6%8d%ae%e5%ba%93%e8%bf%9e%e6%8e%a5","status":"publish","type":"post","link":"https:\/\/note.ui11.cc\/index.php\/2024\/08\/22\/%e6%95%b0%e6%8d%ae%e5%ba%93%e8%bf%9e%e6%8e%a5\/","title":{"rendered":"\u6570\u636e\u5e93\u8fde\u63a5"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>import java.sql.*;\npublic class Main {\n    public static void main(String&#91;] args) {\n        \/\/ \u4fee\u6539\u7528\u6237\u540d\u548c\u5bc6\u7801\n        System.out.println(\"\u8bf7\u8f93\u5165\u8981\u4fee\u6539\u7684\u7528\u6237\u540d\");\n        Scanner sc = new Scanner(System.in);\n        String yonghuming = sc.next();\n        try {\n            Class.forName(\"com.mysql.cj.jdbc.Driver\");\n            String url = \"jdbc:mysql:\/\/localhost:3306\/s0822\";\n            String user = \"root\";\n            String password = \"1234\";\n            Connection c = DriverManager.getConnection(url, user, password);\n            String sql = \"SELECT * FROM user WHERE username = ?\";\n            PreparedStatement p = c.prepareStatement(sql);\n            p.setString(1, yonghuming);\n            ResultSet rs = p.executeQuery();\n            if (rs.next()) {\n                System.out.println(\"\u8bf7\u8f93\u5165\u4f60\u60f3\u66f4\u6539\u7684\u7528\u6237\u540d\");\n                String newusername = sc.next();\n                String sql01 = \"UPDATE user set username = ? WHERE username = ?\";\n                PreparedStatement updateStmt = c.prepareStatement(sql01);\n                updateStmt.setString(1, newusername);\n                updateStmt.setString(2, yonghuming);\n                int affectedRows = updateStmt.executeUpdate();\n                if (affectedRows > 0) {\n                    System.out.println(\"\u606d\u559c\u4f60\uff0c\u8d26\u6237\u540d\u6210\u529f\u4fee\u6539\u4e3a\" + newusername);\n                } else {\n                    System.out.println(\"\u7528\u6237\u540d\u66f4\u65b0\u5931\u8d25\");\n                }\n            } else {\n                System.out.println(\"\u7528\u6237\u540d\u4e0d\u5b58\u5728\");\n            }\n        } catch (ClassNotFoundException e) {\n            System.out.println(\"\u627e\u4e0d\u5230JDBC\u9a71\u52a8\u7c7b\");\n            e.printStackTrace();\n        } catch (SQLException e) {\n            System.out.println(\"\u6570\u636e\u5e93\u64cd\u4f5c\u51fa\u9519\");\n            e.printStackTrace();\n        } finally {\n            sc.close();\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,7],"tags":[],"class_list":["post-271","post","type-post","status-publish","format-standard","hentry","category-javase","category-7"],"_links":{"self":[{"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/posts\/271","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/comments?post=271"}],"version-history":[{"count":1,"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/posts\/271\/revisions"}],"predecessor-version":[{"id":272,"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/posts\/271\/revisions\/272"}],"wp:attachment":[{"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/media?parent=271"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/categories?post=271"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/tags?post=271"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}