{"id":222,"date":"2017-01-28T01:36:20","date_gmt":"2017-01-27T17:36:20","guid":{"rendered":"http:\/\/www.rainweb.site\/?p=222"},"modified":"2017-01-28T01:36:20","modified_gmt":"2017-01-27T17:36:20","slug":"java-aarticle0008","status":"publish","type":"post","link":"http:\/\/rain1024.com\/index.php\/2017\/01\/28\/java-aarticle0008\/","title":{"rendered":"Java\u4f7f\u7528jdbc\u8fde\u63a5mysql\u6570\u636e\u5e93"},"content":{"rendered":"<h3>Java\u4f7f\u7528jdbc\u8fde\u63a5mysql\u6570\u636e\u5e93<\/h3>\n<blockquote><p>\n  \u8fde\u63a5\u65f6\u9700\u8981\u6ce8\u610f\u7684\u51e0\u70b9\uff1a<br \/>\n    1. \u5c06jdbc\u7684jar\u5305\u653e\u5165\u9879\u76ee\u6587\u4ef6lib\u4e2d<br \/>\n    2. \u8bb0\u4f4fmysql\u5b89\u88c5\u65f6\u7684\u7528\u6237\u540d\u548c\u5bc6\u7801<br \/>\n    3. \u5c3d\u91cf\u5c06\u7c7b\u6587\u4ef6\u653e\u5728util\u76ee\u5f55\u4e0b<br \/>\n    4. \u5728\u672c\u5730\u4f7f\u7528\u65f6\u4e00\u822c\u53ea\u9700\u8981\u6539\u6570\u636e\u5e93user\u548cpass\u8fd8\u6709databasename<br \/>\n    5. \u5728\u5176\u4ed6\u7c7b\u4e2d\u8c03\u7528\u5b8c\u6bd5\u540e\u8bb0\u5f97\u5173\u95ed\u8fde\u63a5<br \/>\n    6. \u65b0\u5efa\u4e00\u4e2a\u6587\u4ef6\u540d\u4e3aDBUtil\u518d\u5c06\u4ee3\u7801\u653e\u5165\u5373\u53ef\n<\/p><\/blockquote>\n<pre><code class=\"JAVA\">public class DBUtil {\n    public static String username=\"root\";\n    public static String password=\"root\";\n    public static String url=\"jdbc:mysql:\/\/localhost:3306\/databasename\";\n\n    static{\n        try {\n            Class.forName(\"com.mysql.jdbc.Driver\");\n        } catch (ClassNotFoundException e) {\n            \/\/ TODO Auto-generated catch block\n            e.printStackTrace();\n        }\n    }\n    \/\/\u83b7\u53d6\u5230\u6570\u636e\u5e93\u7684\u94fe\u63a5\n    public static  Connection getConnectDb()\n    {\n        Connection conn=null;\n        try {\n            conn = DriverManager.getConnection(url,username,password);\n        } catch (SQLException e) {\n            \/\/ TODO Auto-generated catch block\n            e.printStackTrace();\n        }\n        return conn;\n    }\n    \/\/\u5173\u95ed\u6570\u636e\u5e93\n    public static void CloseDB(ResultSet rs, PreparedStatement stm, Connection conn)\n    {\n        if(rs!=null)\n        {\n            try {\n                rs.close();\n            } catch (SQLException e) {\n                \/\/ TODO Auto-generated catch block\n                e.printStackTrace();\n            }\n        }\n        if(stm!=null)\n        {\n            try {\n                stm.close();\n            } catch (SQLException e) {\n                \/\/ TODO Auto-generated catch block\n                e.printStackTrace();\n            }\n        }\n        if(conn!=null)\n        {\n            try {\n                conn.close();\n            } catch (SQLException e) {\n                \/\/ TODO Auto-generated catch block\n                e.printStackTrace();\n            }\n        }\n    }\n}\n<\/code><\/pre>\n<h4>\u5982\u679c\u559c\u6b22\u8bf7\u6536\u85cf\uff0c\u6211\u4f1a\u6301\u7eed\u66f4\u65b0\uff0c\u535a\u5ba2\u6682\u65f6\u6ca1\u6709\u4e0a\u4f20\u6587\u4ef6\uff0c\u6709\u9700\u8981mysqljar\u5305\u7684\u53ef\u4ee5\u7ed9\u6211\u53d1\u90ae\u4ef6\uff0c\u6211\u4f1a\u53ca\u65f6\u53d1\u9001\u7ed9\u4f60\u3002\u6700\u540e[<a href=\"http:\/\/84b7da85.wiz01.com\/share\/s\/24JZG50B3QHR23mv6A1JgkeG2qK-O53OQ4Cq2Peijy05Pdw-\" title=\"\u8fd9\u91cc\u662f\u6211\u7b14\u8bb0\u7684\u8fde\u63a5\uff0c\u6709\u9700\u8981\u7684\u53ef\u4ee5\u70b9\u51fb\u67e5\u770b\">\u8fd9\u91cc\u662f\u6211\u7b14\u8bb0\u7684\u8fde\u63a5\uff0c\u6709\u9700\u8981\u7684\u53ef\u4ee5\u70b9\u51fb\u67e5\u770b<\/a>]<\/h4>\n","protected":false},"excerpt":{"rendered":"<p>Java\u4f7f\u7528jdbc\u8fde\u63a5mysql\u6570\u636e\u5e93 \u8fde\u63a5\u65f6\u9700\u8981\u6ce8\u610f\u7684\u51e0\u70b9\uff1a 1. \u5c06jdbc\u7684jar\u5305\u653e\u5165\u9879\u76ee\u6587\u4ef6lib\u2026 <span class=\"read-more\"><a href=\"http:\/\/rain1024.com\/index.php\/2017\/01\/28\/java-aarticle0008\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":2,"featured_media":224,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"aside","meta":{"footnotes":""},"categories":[31],"tags":[46,56,75],"class_list":["post-222","post","type-post","status-publish","format-aside","has-post-thumbnail","hentry","category-java","tag-java","tag-mysql","tag-database","post_format-post-format-aside"],"_links":{"self":[{"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/posts\/222","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/comments?post=222"}],"version-history":[{"count":0,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/posts\/222\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/media\/224"}],"wp:attachment":[{"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/media?parent=222"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/categories?post=222"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/tags?post=222"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}