{"id":109,"date":"2023-02-18T09:57:43","date_gmt":"2023-02-18T01:57:43","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=109"},"modified":"2023-02-18T09:58:03","modified_gmt":"2023-02-18T01:58:03","slug":"jdbc-create-database","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/18\/jdbc-create-database\/","title":{"rendered":"\u4f7f\u7528JDBC\u521b\u5efa\u6570\u636e\u5e93"},"content":{"rendered":"<p>\u4f7f\u7528JDBC\u4e0d\u4ec5\u80fd\u8fde\u63a5\u64cd\u4f5c\u6570\u636e\u5e93\uff0c\u751a\u81f3\u8fd8\u80fd\u521b\u5efa\u6570\u636e\u5e93\uff0c\u53ea\u9700\u8981\u6743\u9650\u5141\u8bb8\u7684\u6761\u4ef6\u4e0b\uff0c\u6bd4\u5982root\u3002<\/p>\n<p><!-- more --><\/p>\n<pre><code class=\"language-java\">public class DBCreateTest {\n    public static String CONN_URL = &quot;jdbc:mysql:\/\/localhost:3306&quot;;\n\n    public static Connection getConn() {\n        Connection conn = null;\n        try {\n            Class.forName(&quot;com.mysql.jdbc.Driver&quot;);\n            conn = DriverManager.getConnection(DBCreateTest.CONN_URL, &quot;root&quot;, &quot;123456&quot;);\n        } catch (SQLException e) {\n            e.printStackTrace();\n        } catch (Exception e) {\n            e.printStackTrace();\n        }\n        return conn;\n    }\n\n    public static void main(String[] args) {\n        String sql = &quot;CREATE DATABASE if not exists `mydb` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;&quot;;\n        try {\n            Statement stmt = DBCreateTest.getConn().createStatement();\n            stmt.executeUpdate(sql);\n            stmt.close();\n            System.out.println(&quot;successed!&quot;);\n        } catch (SQLException e) {\n            e.printStackTrace();\n        }\n    }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528JDBC\u4e0d\u4ec5\u80fd\u8fde\u63a5\u64cd\u4f5c\u6570\u636e\u5e93\uff0c\u751a\u81f3\u8fd8\u80fd\u521b\u5efa\u6570\u636e\u5e93\uff0c\u53ea\u9700\u8981\u6743\u9650\u5141\u8bb8\u7684\u6761\u4ef6\u4e0b\uff0c\u6bd4\u5982root\u3002 public c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[],"class_list":["post-109","post","type-post","status-publish","format-standard","hentry","category-java-basic"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/109","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=109"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/109\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=109"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=109"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=109"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}