{"id":512,"date":"2020-07-14T17:33:27","date_gmt":"2020-07-14T09:33:27","guid":{"rendered":"http:\/\/www.gbase8.cn\/?p=512"},"modified":"2021-03-04T17:20:57","modified_gmt":"2021-03-04T09:20:57","slug":"gbase-8a%e9%9b%86%e7%be%a4jdbc-%e6%89%b9%e9%87%8f%e6%8f%90%e4%ba%a4rewritebatcheds-tatements%e5%8f%82%e6%95%b0%e7%9a%84%e4%bd%bf%e7%94%a8%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a1%b9","status":"publish","type":"post","link":"https:\/\/www.gbase8.cn\/en\/512","title":{"rendered":"\u5357\u5927\u901a\u7528GBase 8a\u96c6\u7fa4JDBC \u6279\u91cf\u63d0\u4ea4rewriteBatchedStatements"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Directory Navigation<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a2b3d0741918\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewbox=\"0 0 24 24\" version=\"1.2\" baseprofile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a2b3d0741918\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.gbase8.cn\/en\/512\/#%E6%B3%A8%E6%84%8F\" >\u6ce8\u610f:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.gbase8.cn\/en\/512\/#%E6%99%AE%E9%80%9A%E5%85%A5%E5%BA%93%E6%96%B9%E5%BC%8F\" >\u666e\u901a\u5165\u5e93\u65b9\u5f0f<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.gbase8.cn\/en\/512\/#%E6%89%B9%E9%87%8F%E5%85%A5%E5%BA%93%E6%96%B9%E5%BC%8F\" >\u6279\u91cf\u5165\u5e93\u65b9\u5f0f<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%B3%A8%E6%84%8F\"><\/span>\u6ce8\u610f:<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>1\u3001\u5fc5\u987b\u662finsert values\u65b9\u5f0f\uff0c\u4e0d\u80fd\u662finsert value\u65b9\u5f0f\uff0c\u6ce8\u610f\u591a\u4e86\u4e00\u4e2a\u5b57\u6bcds\u3002<\/p>\n\n\n\n<p>2\u3001insert values\u65f6\u7684\u8bed\u53e5\u6700\u540e\uff0c\u4e0d\u8981\u6709\u5206\u53f7\uff0c\u5426\u5219\u4f1a\u4ece\u7b2c\u4e8c\u884c\u5f00\u59cb\u51fa\u8bed\u6cd5\u9519\u8bef\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%99%AE%E9%80%9A%E5%85%A5%E5%BA%93%E6%96%B9%E5%BC%8F\"><\/span>\u666e\u901a\u5165\u5e93\u65b9\u5f0f<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u5982\u679c\u4f60\u6709\u5927\u91cf\u7684\u5355\u884c\u6570\u636e\u8981\u5165\u5e93\uff0c\u53ef\u4ee5\u91c7\u7528\u5982\u4e0b\u51e0\u4e2a\u65b9\u6848<\/p>\n\n\n\n<p>1\u3001insert\u65b9\u5f0f\uff0c\u6bcf\u6b21\u4e00\u884c<\/p>\n\n\n\n<p>2\u3001insert \u65b9\u5f0f\uff0c\u6bcf\u6b211000\u884c\uff0c\u6279\u91cf\u63d0\u4ea4<\/p>\n\n\n\n<p>3\u3001\u8f93\u51fa\u6210\u6587\u4ef6\uff0cload\u52a0\u8f7d\u65b9\u5f0f<\/p>\n\n\n\n<p>\u5176\u4e2d\u7b2c\u4e00\u79cd\u6027\u80fd\u6700\u5dee\u3002\u800c\u7b2c\u4e8c\u79cd\uff0c\u672c\u8d28\u4e0a\u7c7b\u4f3c\u5982\u4e0b\u7684\u64cd\u4f5c<\/p>\n\n\n\n<p>set autocommit=0;<br>insert into XXX values ();<br>insert into XXX values ();<br>insert into XXX values ();<br>....<br>commit;<\/p>\n\n\n\n<p>\u8fd9\u79cd\u65b9\u6848\u6027\u80fd\u6bd4\u9010\u884c\u7684\u6027\u80fd\u8981\u597d\u5f88\u591a\u3002 \u53e6\u5916\u4e00\u4e2a\u65b9\u6848\u5c31\u662f<\/p>\n\n\n\n<p>insert into XXX values (),(),(),();<\/p>\n\n\n\n<p>\u4e5f\u5c31\u662f\u901a\u8fc7\u4e00\u4e2aSQL\u8bed\u53e5\uff0c\u591a\u4e2a\u503c\uff0c\u5199\u52301\u4e2aSQL\u91cc\u9762\uff0c\u4e00\u6b21\u6267\u884c\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%89%B9%E9%87%8F%E5%85%A5%E5%BA%93%E6%96%B9%E5%BC%8F\"><\/span>\u6279\u91cf\u5165\u5e93\u65b9\u5f0f<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>gbase \u7684jdbc\u9a71\u52a8\uff0c\u901a\u8fc7rewriteBatchedStatements=true\u53c2\u6570\uff0c\u53ef\u4ee5\u81ea\u52a8\u5c06Batch Insert \u65b9\u5f0f\u7684\u6279\u91cf\u63d0\u4ea4\uff0c\u81ea\u52a8\u91cd\u5199\u6210\u591a\u4e2avalues\u7684\u683c\u5f0f\uff0c\u6765\u63d0\u9ad8\u6027\u80fd\u3002<\/p>\n\n\n\n<p>\u4f46\u7f3a\u70b9\u4e5f\u5b58\u5728\uff0c\u5982\u679c\u4f60\u7684\u6570\u636e\u91cc\u5b58\u5728\u4e86\u5355\u5f15\u53f7\u7b49\uff0c\u6ca1\u6709\u63d0\u524d\u8f6c\u4e49(\u6bd4\u5982\u8f6c\u4e49\u6210\\')\uff0c\u4f1a\u5bfc\u81f4\u62fc\u63a5\u51fa\u6765\u7684SQL\u8bed\u6cd5\u9519\u8bef\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class TestBatchInsert {\r\n\r\n\tpublic static void main(String&#91;] args) {\r\n\t\tConnection conn;\r\n\t\ttry {\r\n\t\t\tconn = DriverManager.getConnection(\r\n\t\t\t\t\t\"jdbc:gbase:\/\/192.168.56.1:52582\/testdb?user=gbase&amp;amp;password=gbase20110531&amp;amp;rewriteBatchedStatements=true&amp;amp;profileSql=true\");\r\n\r\n\t\t\tconn.setAutoCommit(false);\r\n\t\t\tString sql = \"insert into t1 (id,id2,id3,id4) values (?,?,?,?)\";\r\n\t\t\tPreparedStatement prest = conn.prepareStatement(sql);\r\n\r\n\t\t\tfor (int id = 1; id &amp;lt;= 10; id++) {\r\n\t\t\t\tprest.setInt(1, id);\r\n\t\t\t\tprest.setInt(2, id);\r\n\t\t\t\tprest.setInt(3, id);\r\n\t\t\t\tprest.setInt(4, id);\r\n\t\t\t\tprest.addBatch();\r\n\t\t\t}\r\n\t\t\tprest.executeBatch();\r\n\t\t\tconn.commit();\r\n\r\n\t\t\tconn.close();\r\n\t\t} catch (Exception ex) {\r\n\t\t\tex.printStackTrace();\r\n\t\t}\r\n\t}\r\n}<\/code><\/pre>\n\n\n\n<p>\u4e00\u4e2a\u66f4\u5b8c\u6574\u7684\u4f8b\u5b50\u622a\u56fe<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><img loading=\"lazy\" decoding=\"async\" width=\"991\" height=\"855\" src=\"http:\/\/www.gbase8.cn\/wp-content\/uploads\/2020\/07\/image-21.png\" alt=\"\" class=\"wp-image-555\"\/><\/figure>","protected":false},"excerpt":{"rendered":"<p>Base 8a\u96c6\u7fa4JDBC \u6279\u91cf\u63d0\u4ea4rewriteBatchedS tatements\u53c2\u6570\u7684\u4f7f\u7528\u6ce8\u610f\u4e8b\u9879<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[16],"class_list":["post-512","post","type-post","status-publish","format-standard","hentry","category-gbase8a","tag-jdbc"],"_links":{"self":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/512","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/comments?post=512"}],"version-history":[{"count":15,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/512\/revisions"}],"predecessor-version":[{"id":4929,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/512\/revisions\/4929"}],"wp:attachment":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/media?parent=512"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/categories?post=512"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/tags?post=512"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}