{"id":8380,"date":"2021-11-30T14:42:51","date_gmt":"2021-11-30T06:42:51","guid":{"rendered":"https:\/\/www.gbase8.cn\/?p=8380"},"modified":"2021-11-30T14:42:52","modified_gmt":"2021-11-30T06:42:52","slug":"gbase-8a-%e9%80%9a%e8%bf%87jdbc%e5%ae%9e%e7%8e%b0%e7%ae%80%e5%8d%95%e8%b4%9f%e8%bd%bd%e5%9d%87%e8%a1%a1%e7%9a%84%e6%b5%8b%e8%af%95%e6%a0%b7%e4%be%8b","status":"publish","type":"post","link":"https:\/\/www.gbase8.cn\/en\/8380","title":{"rendered":"\u5357\u5927\u901a\u7528GBase 8a \u901a\u8fc7JDBC\u5b9e\u73b0\u7b80\u5355\u8d1f\u8f7d\u5747\u8861\u7684\u6d4b\u8bd5\u6837\u4f8b"},"content":{"rendered":"<p>GBase 8a \u7684\u6240\u6709\u8c03\u5ea6\u8282\u70b9(coordinator)\u5747\u53ef\u4ee5\u5bf9\u5916\u63d0\u4f9b\u5b8c\u6574\u7684\u670d\u52a1\uff0c\u540c\u65f6\u5176JDBC\/ODBC\/C API\u7b49\u9a71\u52a8\uff0c\u5b9e\u73b0\u4e86\u7b80\u5355\u7684\u57fa\u4e8e\u8f6e\u8be2(round-robin\uff09\u7684\u8d1f\u8f7d\u5747\u8861\u673a\u5236\uff0c\u672c\u6587\u4ecb\u7ecdJDBC\u7684\u4e00\u4e2a\u6837\u4f8b\u3002<\/p>\n\n\n\n<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-6a2b44b4aa01b\" 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-6a2b44b4aa01b\"  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\/8380\/#%E5%8F%82%E8%80%83\" >\u53c2\u8003<\/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\/8380\/#%E7%8E%AF%E5%A2%83\" >\u73af\u5883<\/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\/8380\/#%E4%BB%A3%E7%A0%81\" >\u4ee3\u7801<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.gbase8.cn\/en\/8380\/#%E8%BF%90%E8%A1%8C%E6%95%88%E6%9E%9C\" >\u8fd0\u884c\u6548\u679c<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.gbase8.cn\/en\/8380\/#%E6%80%BB%E7%BB%93\" >Summary<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%8F%82%E8%80%83\"><\/span>\u53c2\u8003<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E7%8E%AF%E5%A2%83\"><\/span>\u73af\u5883<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>2\u8282\u70b9\u96c6\u7fa4\uff0c\u6d4b\u8bd510\u4e2a\u8fde\u63a5\uff0c\u662f\u5426\u5747\u8861\u7684\u5206\u5e03\u52302\u4e2a\u8282\u70b9\u4e0a\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;gbase@862b43 ~]$ gcadmin\r\nCLUSTER STATE:  ACTIVE\r\nCLUSTER MODE:   NORMAL\r\n\r\n=================================================================\r\n|             GBASE COORDINATOR CLUSTER INFORMATION             |\r\n=================================================================\r\n|   NodeName   |     IpAddress     |gcware |gcluster |DataState |\r\n-----------------------------------------------------------------\r\n| coordinator1 |    10.0.2.106     | OPEN  |  OPEN   |    0     |\r\n-----------------------------------------------------------------\r\n| coordinator2 |    10.0.2.107     | OPEN  |  OPEN   |    0     |\r\n-----------------------------------------------------------------\r\n=============================================================\r\n|              GBASE DATA CLUSTER INFORMATION               |\r\n=============================================================\r\n|NodeName |     IpAddress     |gnode |syncserver |DataState |\r\n-------------------------------------------------------------\r\n|  node1  |    10.0.2.106     | OPEN |   OPEN    |    0     |\r\n-------------------------------------------------------------\r\n|  node2  |    10.0.2.107     | OPEN |   OPEN    |    0     |\r\n-------------------------------------------------------------\r\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E4%BB%A3%E7%A0%81\"><\/span>\u4ee3\u7801<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.sql.Connection;\r\nimport java.sql.DriverManager;\r\nimport java.sql.Statement;\r\n\r\npublic class Test {\r\n\r\n        public static void main(String&#91;] args) throws Exception {\r\n\r\n                for (int i = 1; i &lt;= 10; i++) {\r\n                        new TestThread(i).start();\r\n                       Thread.sleep(100);\r\n                }\r\n        }\r\n}\r\n\r\nclass TestThread extends Thread {\r\n        private int id;\r\n        public TestThread(int id) {\r\n                this.id = id;\r\n        }\r\n        public void run() {\r\n                Connection conn = null;\r\n                try {\r\n                        conn = DriverManager.getConnection(\r\n                            \"jdbc:gbase:\/\/10.0.2.106\/testdb?user=gbase&amp;password=gbase20110531&amp;failoverEnable=true&amp;hostList=10.0.2.107&amp;gclusterId=vmax\");\r\n                        Statement stat = conn.createStatement();\r\n                        stat.execute(\"select sleep(10)\");\r\n\r\n                        conn.close();\r\n                } catch (Exception ex) {\r\n                        System.out.println(id);\r\n                        ex.printStackTrace();\r\n                }\r\n        }\r\n}\r\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E8%BF%90%E8%A1%8C%E6%95%88%E6%9E%9C\"><\/span>\u8fd0\u884c\u6548\u679c<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>2\u4e2a\u8282\u70b9\uff0c\u6bcf\u4e2a\u4e0a\u67095\u4e2aSQL\u5728\u8fd0\u884c\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\r&#91;gbase@localhost ~]$ gccli -h10.0.2.106 -e\"show processlist\"\r\n+----+-----------------+------------------+--------+---------+------+---------------------------+------------------+\r\n| Id | User            | Host             | db     | Command | Time | State                     | Info             |\r\n+----+-----------------+------------------+--------+---------+------+---------------------------+------------------+\r\n|  1 | event_scheduler | localhost        | NULL   | Daemon  |  564 | Waiting for cluster mutex | NULL             |\r\n| 75 | gbase           | 10.0.2.106:42850 | testdb | Query   |    3 | checking permissions      | select sleep(10) |\r\n| 76 | gbase           | 10.0.2.106:42854 | testdb | Query   |    3 | checking permissions      | select sleep(10) |\r\n| 77 | gbase           | 10.0.2.106:42856 | testdb | Query   |    3 | checking permissions      | select sleep(10) |\r\n| 78 | gbase           | 10.0.2.106:42860 | testdb | Query   |    3 | checking permissions      | select sleep(10) |\r\n| 79 | gbase           | 10.0.2.106:42864 | testdb | Query   |    3 | checking permissions      | select sleep(10) |\r\n| 80 | root            | 10.0.2.107:54660 | NULL   | Query   |    0 | NULL                      | show processlist |\r\n+----+-----------------+------------------+--------+---------+------+---------------------------+------------------+\r\n&#91;gbase@localhost ~]$ gccli -h10.0.2.107 -e\"show processlist\"\r\n+----+-----------------+------------------+--------+---------+------+-----------------------------+------------------+\r\n| Id | User            | Host             | db     | Command | Time | State                       | Info             |\r\n+----+-----------------+------------------+--------+---------+------+-----------------------------+------------------+\r\n|  1 | event_scheduler | localhost        | NULL   | Daemon  |  560 | Waiting for next activation | NULL             |\r\n| 27 | gbase           | 10.0.2.106:50112 | testdb | Query   |    5 | checking permissions        | select sleep(10) |\r\n| 28 | gbase           | 10.0.2.106:50114 | testdb | Query   |    5 | checking permissions        | select sleep(10) |\r\n| 29 | gbase           | 10.0.2.106:50118 | testdb | Query   |    5 | checking permissions        | select sleep(10) |\r\n| 30 | gbase           | 10.0.2.106:50124 | testdb | Query   |    5 | checking permissions        | select sleep(10) |\r\n| 31 | gbase           | 10.0.2.106:50128 | testdb | Query   |    5 | checking permissions        | select sleep(10) |\r\n| 32 | root            | 10.0.2.107:58220 | NULL   | Query   |    0 | NULL                        | show processlist |\r\n+----+-----------------+------------------+--------+---------+------+-----------------------------+------------------+\r\n&#91;gbase@localhost ~]$\r\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%80%BB%E7%BB%93\"><\/span>Summary<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u8be5\u8d1f\u8f7d\u5747\u8861\u529f\u80fd\u5b9e\u73b0\u5f88\u7b80\u5355\uff0c\u6ca1\u6709\u5224\u65ad\u8282\u70b9\u7684\u771f\u5b9e\u8d1f\u8f7d\u3001\u8fd0\u884c\u4e2d\u7684SQL\u6570\u91cf\u7b49\uff0c\u53ea\u662f\u7b80\u5355\u7684\u5faa\u73af\u3002\u5982\u679c\u60f3\u5b9e\u73b0\u66f4\u597d\u7684\uff0c\u5efa\u8bae\u91c7\u7528F5\u8bbe\u5907\uff0c\u6216\u8005\u7528lvs\u7b49\u7b2c\u4e09\u65b9\u8f6f\u4ef6\u5b9e\u73b0\u3002<\/p>\n\n\n\n<p>\u53e6\u5916\uff0c\u5982\u679c\u4f7f\u7528\u4e86\u8fde\u63a5\u6c60\uff0c\u90a3\u4e48\u53ea\u80fd\u4fdd\u8bc1\u8fde\u63a5\u6c60\u91cc\u6bcf\u4e2a\u65b0\u5efa\u7684\u8fde\u63a5\u662f\u5faa\u73af\u4ea7\u751f\u7684\uff0c\u4f46\u4e0d\u80fd\u4fdd\u8bc1\u5e94\u7528\u4ece\u8fde\u63a5\u6c60\u91cc\u83b7\u5f97\u8fde\u63a5\u65f6\uff0c\u4e5f\u662f\u5faa\u73af\u7684\u3002\u5982\u679c\u670d\u52a1\u5668\u6709\u8282\u70b9\u6545\u969c\uff0c\u90a3\u4e48\u8fde\u63a5\u6c60\u91cc\u5c06\u4e0d\u5305\u542b\u8be5\u8282\u70b9\u7684\u8fde\u63a5\uff0c\u5373\u4f7f\u8282\u70b9\u6062\u590d\u6b63\u5e38\uff0c\u9664\u975e\u8fde\u63a5\u6c60\u5237\u65b0\uff0c\u5426\u5219\u4f9d\u7136\u4fdd\u6301\u73b0\u72b6\u3002<\/p>","protected":false},"excerpt":{"rendered":"<p>\u5357\u5927\u901a\u7528GBase 8a \u7684\u6240\u6709\u8c03\u5ea6\u8282\u70b9(coordinator)\u5747\u53ef\u4ee5\u5bf9\u5916\u63d0\u4f9b\u5b8c\u6574\u7684\u670d\u52a1\uff0c\u540c\u65f6\u5176JDBC\/ODBC\/C API\u7b49\u9a71\u52a8\uff0c\u5b9e\u73b0\u4e86\u7b80\u5355\u7684\u57fa\u4e8e\u8f6e\u8be2(round-robin\uff09\u7684\u8d1f\u8f7d\u5747\u8861\u673a\u5236\uff0c\u672c\u6587\u4ecb\u7ecdJDBC\u7684\u4e00\u4e2a\u6837\u4f8b\u3002<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[16],"class_list":["post-8380","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\/8380","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=8380"}],"version-history":[{"count":4,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/8380\/revisions"}],"predecessor-version":[{"id":8384,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/8380\/revisions\/8384"}],"wp:attachment":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/media?parent=8380"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/categories?post=8380"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/tags?post=8380"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}