
{"id":2364,"date":"2020-10-14T13:20:03","date_gmt":"2020-10-14T05:20:03","guid":{"rendered":"http:\/\/admin.evshou.com\/?p=2364"},"modified":"2020-10-15T15:41:27","modified_gmt":"2020-10-15T07:41:27","slug":"2020javaweb%e6%95%99%e7%a8%8b%e4%b9%8bjdbc%e5%ae%9e%e7%8e%b0%e7%94%a8%e6%88%b7%e7%99%bb%e5%bd%95","status":"publish","type":"post","link":"https:\/\/www.9713job.com\/?p=2364","title":{"rendered":"2020Javaweb\u6559\u7a0b\u4e4bJDBC\u5b9e\u73b0\u7528\u6237\u767b\u5f55"},"content":{"rendered":"<h3>2020Javaweb\u6559\u7a0b\u4e4bJDBC\u5b9e\u73b0\u7528\u6237\u767b\u5f55<\/h3>\n<pre>import java.sql.*;\r\nimport java.util.Scanner;\r\n\r\npublic class JDBCforLogin {\r\n    public static void main(String[] args) {\r\n        Scanner sc=new Scanner(System.in);\r\n        System.out.println(\"\u8bf7\u8f93\u5165\u7528\u6237\u540d\uff1a\");\r\n        String username=sc.nextLine();\r\n        System.out.println(\"\u8bf7\u8f93\u5165\u5bc6\u7801\uff1a\");\r\n        String password=sc.nextLine();\r\n        login(username,password);\r\n    }\r\n<!--more-->\r\n\r\n\r\n    public static void login(String username,String password){\r\n        Connection connection=null;\r\n        PreparedStatement PreparedStatement=null;\r\n        ResultSet resultSet=null;\r\n        try{\r\n            Class.forName(\"com.mysql.jdbc.Driver\");\r\n            connection = DriverManager.getConnection(\"jdbc:mysql:\/\/localhost:3306\/demos\", \"root\", \"root\");\r\n            \/\/ ? \u4e3a\u5360\u4f4d\u7b26\r\n            String sql=\"select username,password from users where username=? and password=?\";\r\n            \/\/ \u9884\u7f16\u8bd1sql\u8bed\u53e5\r\n            PreparedStatement=connection.prepareStatement(sql);\r\n            \/\/\u4e3a\u6bcf\u4e2a\u5360\u4f4d\u7b26\u8d4b\u4e88\u4e00\u4e2a\u503c\r\n            PreparedStatement.setString(1,username);\r\n            PreparedStatement.setString(2,password);\r\n            resultSet = PreparedStatement.executeQuery();\r\n            if (resultSet.next()) {\r\n                System.out.println(\"\u767b\u5f55\u6210\u529f\");\r\n            }else System.out.println(\"\u767b\u5f55\u5931\u8d25\");\r\n        }catch (Exception e){}finally {\r\n            try {\r\n                if (resultSet != null) {\r\n                    resultSet.close();\r\n                }\r\n                if (PreparedStatement != null) {\r\n                    PreparedStatement.close();\r\n                }\r\n                if (connection != null) {\r\n                    connection.close();\r\n                }\r\n            } catch (SQLException e) {}\r\n        }\r\n    }\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>2020Javaweb\u6559\u7a0b\u4e4bJDBC\u5b9e\u73b0\u7528\u6237\u767b\u5f55 import java.sql.*; import java [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-2364","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2364","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2364"}],"version-history":[{"count":1,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2364\/revisions"}],"predecessor-version":[{"id":2365,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2364\/revisions\/2365"}],"wp:attachment":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2364"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2364"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2364"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}