{"id":203570,"date":"2025-05-22T11:45:24","date_gmt":"2025-05-22T03:45:24","guid":{"rendered":"https:\/\/server.hk\/cnblog\/203570\/"},"modified":"2025-05-22T11:45:24","modified_gmt":"2025-05-22T03:45:24","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-java-%e5%b7%a5%e5%85%b7%e7%b1%bb%e6%89%a7%e8%a1%8c%e6%95%b0%e6%8d%ae%e5%ba%93%e8%84%9a%e6%9c%ac%e6%96%87%e4%bb%b6%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/203570\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 Java \u5de5\u5177\u7c7b\u6267\u884c\u6570\u636e\u5e93\u811a\u672c\u6587\u4ef6\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u5982\u4f55\u4f7f\u7528 Java \u5de5\u5177\u7c7b\u6267\u884c\u6570\u636e\u5e93\u811a\u672c\u6587\u4ef6\uff1f<\/h1>\n<p>\u5927\u5bb6\u597d\uff0c\u4eca\u5929\u672c\u4eba\u7ed9\u5927\u5bb6\u5e26\u6765\u6587\u7ae0<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u5982\u4f55\u4f7f\u7528 Java \u5de5\u5177\u7c7b\u6267\u884c\u6570\u636e\u5e93\u811a\u672c\u6587\u4ef6\uff1f\u300b<\/span>\uff0c\u6587\u4e2d\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span><\/span>\uff0c\u5982\u679c\u4f60\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u90a3\u5c31\u8bf7\u5404\u4f4d\u670b\u53cb\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427~\u5e0c\u671b\u80fd\u771f\u6b63\u5e2e\u5230\u4f60\u4eec\uff0c\u8c22\u8c22\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241112\/17313773606732b8d0bfb2a.jpg\" class=\"aligncenter\"><\/p>\n<h2>java \u6267\u884c\u6570\u636e\u5e93\u811a\u672c\u6587\u4ef6\u5de5\u5177\u7c7b\u4ecb\u7ecd<\/h2>\n<p><strong>\u95ee\u9898\uff1a<\/strong><\/p>\n<p>\u5982\u4f55\u4f7f\u7528 java \u5de5\u5177\u7c7b\u6267\u884c\u6570\u636e\u5e93\u811a\u672c\u6587\u4ef6\uff0c\u5982 oracle \u7684\u811a\u672c\u6587\u4ef6\uff1f<\/p>\n<p><strong>\u7b54\u6848\uff1a<\/strong><\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528 java \u4e2d\u7684 jdbctemplate \u7c7b\u6765\u6267\u884c\u6570\u636e\u5e93\u811a\u672c\u6587\u4ef6\u3002\u4ee5\u4e0b\u662f\u5177\u4f53\u7684\u5b9e\u65bd\u6b65\u9aa4\uff1a<\/p>\n<p><strong>1. \u5bfc\u5165\u5fc5\u8981\u7684\u4f9d\u8d56<\/strong><\/p>\n<p>\u5728 maven \u9879\u76ee\u7684 pom.xml \u6587\u4ef6\u4e2d\u5bfc\u5165 oracle \u9a71\u52a8\u5305\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>&lt;dependency&gt;\n    &lt;groupid&gt;com.oracle.database.jdbc&lt;\/groupid&gt;\n    &lt;artifactid&gt;ojdbc10&lt;\/artifactid&gt;\n    &lt;version&gt;19.15.0.0.1&lt;\/version&gt;\n&lt;\/dependency&gt;<\/pre>\n<p><strong>2. \u521b\u5efa jdbctemplate \u5b9e\u4f8b<\/strong><\/p>\n<pre>import org.springframework.jdbc.core.jdbctemplate;\nimport javax.sql.datasource;\n\npublic class sqlexecutor {\n\n    private jdbctemplate jdbctemplate;\n\n    public sqlexecutor(datasource datasource) {\n        this.jdbctemplate = new jdbctemplate(datasource);\n    }\n\n    \/\/ \u6267\u884c sql \u811a\u672c\u6587\u4ef6\n    public void execute(string sqlscriptpath) {\n        jdbctemplate.execute(new string(files.readallbytes(paths.get(sqlscriptpath))));\n    }\n}<\/pre>\n<p><strong>3. \u4f7f\u7528 jdbctemplate \u6267\u884c\u811a\u672c\u6587\u4ef6<\/strong><\/p>\n<pre>\/\/ \u521b\u5efa SQLExecutor \u5b9e\u4f8b\nSQLExecutor sqlExecutor = new SQLExecutor(dataSource);\n\n\/\/ \u6267\u884c SQL \u811a\u672c\u6587\u4ef6\nsqlExecutor.execute(\"path\/to\/myfile.sql\");<\/pre>\n<p>\u901a\u8fc7\u4f7f\u7528 jdbctemplate\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u6267\u884c\u5b58\u50a8\u8fc7\u7a0b\u548c\u6570\u636e\u5e93\u811a\u672c\u6587\u4ef6\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301\uff01\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8\u516c\u4f17\u53f7\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u4f7f\u7528 Java \u5de5\u5177\u7c7b\u6267\u884c\u6570&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-203570","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/203570","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=203570"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/203570\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=203570"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=203570"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=203570"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}