{"id":64491,"date":"2025-05-03T09:40:10","date_gmt":"2025-05-03T01:40:10","guid":{"rendered":"https:\/\/fwq.ai\/blog\/64491\/"},"modified":"2025-05-03T09:40:10","modified_gmt":"2025-05-03T01:40:10","slug":"java-jdbc%e8%83%bd%e5%90%a6%e5%b0%86%e6%9f%a5%e8%af%a2%e7%bb%93%e6%9e%9c%e8%bd%ac%e6%8d%a2%e4%b8%bahashmap%ef%bc%9f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/64491\/","title":{"rendered":"Java JDBC\u80fd\u5426\u5c06\u67e5\u8be2\u7ed3\u679c\u8f6c\u6362\u4e3aHashMap\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173064024555082.jpg\" class=\"aligncenter\" title=\"Java JDBC\u80fd\u5426\u5c06\u67e5\u8be2\u7ed3\u679c\u8f6c\u6362\u4e3aHashMap\uff1f\u63d2\u56fe\" alt=\"Java JDBC\u80fd\u5426\u5c06\u67e5\u8be2\u7ed3\u679c\u8f6c\u6362\u4e3aHashMap\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>java jdbc\u80fd\u5426\u8fd4\u56dehashmap\uff1f<\/strong><\/p>\n<p>\u4e2d\u4f7f\u7528py.cursors.dictcursor\u53ef\u4ee5\u5c06\u6570\u636e\u5e93\u67e5\u8be2\u7ed3\u679c\u8f6c\u6362\u4e3a\u5b57\u5178\u683c\u5f0f\u3002\u90a3\u4e48\uff0cjava jdbc\u662f\u5426\u6709\u7c7b\u4f3c\u7684\u529f\u80fd\uff0c\u53ef\u4ee5\u5c06\u7ed3\u679c\u8f6c\u6362\u4e3ahashmap\uff1f<\/p>\n<p><strong>\u7b54\u6848\uff1a<\/strong><\/p>\n<p>java jdbc\u8fd4\u56de\u7684\u6570\u636e\u7ed3\u6784\u662fresultsetrow\uff0c\u672c\u8eab\u6ca1\u6709\u76f4\u63a5\u63d0\u4f9b\u8fd4\u56dehashmap\u7684\u529f\u80fd\u3002\u4f46\u662f\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee3\u7406\u7684\u65b9\u5f0f\u5c06\u7ed3\u679c\u96c6\u8f6c\u6362\u4e3ahashmap\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p><strong>\u4ee3\u7406\u5b9e\u73b0\uff1a<\/strong><\/p>\n<pre>import java.sql.resultset;\nimport java.util.hashmap;\n\npublic class resultsethashmapproxy implements resultset {\n  private resultset resultset;\n\n  public resultsethashmapproxy(resultset resultset) {\n    this.resultset = resultset;\n  }\n\n  \/\/ \u5b9e\u73b0resultset\u63a5\u53e3\u65b9\u6cd5\uff0c\u5c06\u7ed3\u679c\u8f6c\u6362\u6210hashmap\n  @override\n  public hashmap&lt;string, object&gt; next() {\n    hashmap&lt;string, object&gt; row = new hashmap&lt;&gt;();\n    try {\n      int columncount = resultset.getmetadata().getcolumncount();\n      for (int i = 1; i &lt;= columncount; i++) {\n        string columnname = resultset.getmetadata().getcolumnname(i);\n        object columnvalue = resultset.getobject(i);\n        row.put(columnname, columnvalue);\n      }\n    } catch (exception e) {\n      \/\/ \u5904\u7406\u5f02\u5e38\n    }\n    return row;\n  }\n\n  \/\/ \u5176\u4ed6resultset\u63a5\u53e3\u65b9\u6cd5\u7684\u5b9e\u73b0...\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528\u4ee3\u7406\uff1a<\/strong><\/p>\n<pre>\/\/ \u5047\u8bbers\u662f\u67e5\u8be2\u7ed3\u679c\u96c6\nResultSetHashMapProxy proxy = new ResultSetHashMapProxy(rs);\nwhile (proxy.next() != null) {\n  HashMap&lt;String, Object&gt; row = proxy.next();\n  \/\/ \u5904\u7406\u884c\u6570\u636e\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<p>\u4f7f\u7528\u4ee3\u7406\u65b9\u5f0f\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u51e0\u70b9\uff1a<\/p>\n<ul>\n<li>\u4ee3\u7406\u4f1a\u589e\u52a0\u989d\u5916\u7684\u5185\u5b58\u5f00\u9500\uff0c\u6027\u80fd\u53ef\u80fd\u7565\u6709\u4e0b\u964d\u3002<\/li>\n<li>resultsethashmapproxy\u4ec5\u5904\u7406\u4e86\u4e00\u884c\u7684\u6570\u636e\uff0c\u5982\u679c\u67e5\u8be2\u7ed3\u679c\u6709\u591a\u884c\uff0c\u9700\u8981\u901a\u8fc7\u5faa\u73af\u7684\u65b9\u5f0f\u83b7\u53d6\u6bcf\u4e00\u884c\u6570\u636e\u3002<\/li>\n<li>resultset\u63a5\u53e3\u4e2d\u7684\u5176\u4ed6\u65b9\u6cd5\u53ef\u80fd\u9700\u8981\u5355\u72ec\u4ee3\u7406\u5b9e\u73b0\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fJava JDBC\u80fd\u5426\u5c06\u67e5\u8be2\u7ed3\u679c\u8f6c\u6362\u4e3aHashMap\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8IDCBABY\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>java jdbc\u80fd\u5426\u8fd4\u56dehashmap\uff1f \u4e2d\u4f7f\u7528py.cursors.dictcursor\u53ef\u4ee5\u5c06\u6570\u636e\u5e93\u67e5\u8be2\u7ed3\u679c\u8f6c\u6362\u4e3a\u5b57\u5178\u683c\u5f0f\u3002\u90a3\u4e48\uff0cjava jdbc\u662f\u5426\u6709\u7c7b\u4f3c\u7684\u529f\u80fd\uff0c\u53ef\u4ee5\u5c06\u7ed3\u679c\u8f6c\u6362\u4e3ahashmap\uff1f \u7b54\u6848\uff1a java jdbc\u8fd4\u56de\u7684\u6570\u636e\u7ed3\u6784\u662fresultsetrow\uff0c\u672c\u8eab\u6ca1\u6709\u76f4\u63a5\u63d0\u4f9b\u8fd4\u56dehashmap\u7684\u529f\u80fd\u3002\u4f46\u662f\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee3\u7406\u7684\u65b9\u5f0f\u5c06\u7ed3\u679c\u96c6\u8f6c\u6362\u4e3ahashmap\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u4ee3\u7406\u5b9e\u73b0\uff1a import java.sql.resultset; import java.util.hashmap; public class resultsethashmapproxy implements resultset { private resultset resultset; public resultsethashmapproxy(resultset resultset) { this.resultset = resultset; } \/\/ \u5b9e\u73b0resultset\u63a5\u53e3\u65b9\u6cd5\uff0c\u5c06\u7ed3\u679c\u8f6c\u6362\u6210hashmap @override public hashmap&lt;string, object&gt; next() { hashmap&lt;string, object&gt; row = new hashmap&lt;&gt;(); try { int columncount = resultset.getmetadata().getcolumncount(); for (int i = 1; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-64491","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/64491","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=64491"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/64491\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=64491"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=64491"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=64491"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}