{"id":7053,"date":"2024-11-14T15:23:41","date_gmt":"2024-11-14T07:23:41","guid":{"rendered":"https:\/\/fwq.ai\/blog\/7053\/"},"modified":"2024-11-14T15:23:41","modified_gmt":"2024-11-14T07:23:41","slug":"jdbc-%e4%b8%ad%e7%9a%84-executequery-%e5%92%8c-executeupdate-%e6%96%b9%e6%b3%95%ef%bc%9a%e5%ae%83%e4%bb%ac%e7%9a%84%e5%8c%ba%e5%88%ab%e6%98%af%e4%bb%80%e4%b9%88%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/7053\/","title":{"rendered":"JDBC \u4e2d\u7684 executeQuery \u548c executeUpdate \u65b9\u6cd5\uff1a\u5b83\u4eec\u7684\u533a\u522b\u662f\u4ec0\u4e48\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173036106322874.jpg\" class=\"aligncenter\" title=\"JDBC \u4e2d\u7684 executeQuery \u548c executeUpdate \u65b9\u6cd5\uff1a\u5b83\u4eec\u7684\u533a\u522b\u662f\u4ec0\u4e48\uff1f\u63d2\u56fe\" alt=\"JDBC \u4e2d\u7684 executeQuery \u548c executeUpdate \u65b9\u6cd5\uff1a\u5b83\u4eec\u7684\u533a\u522b\u662f\u4ec0\u4e48\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>jdbc\u4e2d\u7684executequery\u548cexecuteupdate\u65b9\u6cd5\uff1a\u7406\u89e3\u5176\u548c\u542b\u4e49<\/strong><\/p>\n<p>\u5728jdbc\u4e2d\uff0cexecutequery\u548cexecuteupdate\u65b9\u6cd5\u662f\u4e24\u4e2a\u5e38\u7528\u7684\u65b9\u6cd5\uff0c\u7528\u4e8e\u4e0e\u6570\u636e\u5e93\u4ea4\u4e92\u3002\u5b83\u4eec\u7684\u4e3b\u8981\u533a\u522b\u5728\u4e8e\u529f\u80fd\u548c\u8fd4\u56de\u503c\u7c7b\u578b\uff1a<\/p>\n<ul>\n<li> <strong>executequery\u65b9\u6cd5\uff1a<\/strong>\u7528\u4e8e\u6267\u884c\u67e5\u8be2\u8bed\u53e5\uff0c\u5e76\u8fd4\u56de\u67e5\u8be2\u7ed3\u679c\u96c6\uff08resultset\u5bf9\u8c61\uff09\uff0c\u5176\u4e2d\u5305\u542b\u67e5\u8be2\u7ed3\u679c\u3002<\/li>\n<li> <strong>executeupdate\u65b9\u6cd5\uff1a<\/strong>\u7528\u4e8e\u6267\u884c\u66f4\u65b0\u8bed\u53e5\uff08\u5982insert\u3001update\u3001delete\uff09\uff0c\u5e76\u8fd4\u56de\u53d7\u5f71\u54cd\u884c\u7684\u6570\u91cf\uff08int\u7c7b\u578b\uff09\u3002<\/li>\n<\/ul>\n<p>\u5bf9\u4e8eexecuteupdate\u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u7c7b\u578bint\uff0c\u5b83\u7684\u542b\u4e49\u662f\uff1a<\/p>\n<ul>\n<li>\u5982\u679c\u6267\u884c\u7684\u662fdml\uff08\u6570\u636e\u64cd\u4f5c\u8bed\u8a00\uff09\u8bed\u53e5\uff0c\u5219\u8fd4\u56de\u53d7\u5f71\u54cd\u884c\u7684\u6570\u91cf\uff08\u589e\u3001\u5220\u3001\u6539\u6d89\u53ca\u7684\u884c\u6570\uff09\u3002<\/li>\n<li>\u5982\u679c\u6267\u884c\u7684\u662f\u4e0d\u8fd4\u56de\u4efb\u4f55\u5185\u5bb9\u7684\uff0c\u5219\u8fd4\u56de0\u3002<\/li>\n<\/ul>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre>int rowCount = statement.executeUpdate(\"DELETE FROM table_name WHERE id = 10\"); \/\/\u8fd4\u56de\u88ab\u5220\u9664\u7684\u884c\u6570\nResultSet resultSet = statement.executeQuery(\"SELECT * FROM table_name\"); \/\/\u8fd4\u56de\u67e5\u8be2\u7ed3\u679c\u96c6<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u7406\u89e3\u8fd9\u4e24\u79cd\u65b9\u6cd5\u7684\u533a\u522b\u5bf9\u4e8e\u4f7f\u7528jdbc\u8fdb\u884c\u6570\u636e\u5e93\u64cd\u4f5c\u975e\u5e38\u91cd\u8981\u3002executequery\u65b9\u6cd5\u7528\u4e8e\u68c0\u7d22\u6570\u636e\uff0cexecuteupdate\u65b9\u6cd5\u7528\u4e8e\u4fee\u6539\u6570\u636e\u3002executeupdate\u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u53ef\u4ee5\u7528\u6765\u786e\u5b9a\u64cd\u4f5c\u662f\u5426\u6210\u529f\uff0c\u5e76\u83b7\u53d6\u6240\u5f71\u54cd\u7684\u884c\u6570\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fJDBC \u4e2d\u7684 executeQuery \u548c executeUpdate \u65b9\u6cd5\uff1a\u5b83\u4eec\u7684\u662f\u4ec0\u4e48\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>jdbc\u4e2d\u7684executequery\u548cexecuteupdate\u65b9\u6cd5\uff1a\u7406\u89e3\u5176\u548c\u542b\u4e49 \u5728jdbc\u4e2d\uff0cexecutequery\u548cexecuteupdate\u65b9\u6cd5\u662f\u4e24\u4e2a\u5e38\u7528\u7684\u65b9\u6cd5\uff0c\u7528\u4e8e\u4e0e\u6570\u636e\u5e93\u4ea4\u4e92\u3002\u5b83\u4eec\u7684\u4e3b\u8981\u533a\u522b\u5728\u4e8e\u529f\u80fd\u548c\u8fd4\u56de\u503c\u7c7b\u578b\uff1a executequery\u65b9\u6cd5\uff1a\u7528\u4e8e\u6267\u884c\u67e5\u8be2\u8bed\u53e5\uff0c\u5e76\u8fd4\u56de\u67e5\u8be2\u7ed3\u679c\u96c6\uff08resultset\u5bf9\u8c61\uff09\uff0c\u5176\u4e2d\u5305\u542b\u67e5\u8be2\u7ed3\u679c\u3002 executeupdate\u65b9\u6cd5\uff1a\u7528\u4e8e\u6267\u884c\u66f4\u65b0\u8bed\u53e5\uff08\u5982insert\u3001update\u3001delete\uff09\uff0c\u5e76\u8fd4\u56de\u53d7\u5f71\u54cd\u884c\u7684\u6570\u91cf\uff08int\u7c7b\u578b\uff09\u3002 \u5bf9\u4e8eexecuteupdate\u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u7c7b\u578bint\uff0c\u5b83\u7684\u542b\u4e49\u662f\uff1a \u5982\u679c\u6267\u884c\u7684\u662fdml\uff08\u6570\u636e\u64cd\u4f5c\u8bed\u8a00\uff09\u8bed\u53e5\uff0c\u5219\u8fd4\u56de\u53d7\u5f71\u54cd\u884c\u7684\u6570\u91cf\uff08\u589e\u3001\u5220\u3001\u6539\u6d89\u53ca\u7684\u884c\u6570\uff09\u3002 \u5982\u679c\u6267\u884c\u7684\u662f\u4e0d\u8fd4\u56de\u4efb\u4f55\u5185\u5bb9\u7684\uff0c\u5219\u8fd4\u56de0\u3002 \u4f8b\u5982\uff1a int rowCount = statement.executeUpdate(&#8220;DELETE FROM table_name WHERE id = 10&#8221;); \/\/\u8fd4\u56de\u88ab\u5220\u9664\u7684\u884c\u6570 ResultSet resultSet = statement.executeQuery(&#8220;SELECT * FROM table_name&#8221;); \/\/\u8fd4\u56de\u67e5\u8be2\u7ed3\u679c\u96c6 \u767b\u5f55\u540e\u590d\u5236 \u7406\u89e3\u8fd9\u4e24\u79cd\u65b9\u6cd5\u7684\u533a\u522b\u5bf9\u4e8e\u4f7f\u7528jdbc\u8fdb\u884c\u6570\u636e\u5e93\u64cd\u4f5c\u975e\u5e38\u91cd\u8981\u3002executequery\u65b9\u6cd5\u7528\u4e8e\u68c0\u7d22\u6570\u636e\uff0cexecuteupdate\u65b9\u6cd5\u7528\u4e8e\u4fee\u6539\u6570\u636e\u3002executeupdate\u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u53ef\u4ee5\u7528\u6765\u786e\u5b9a\u64cd\u4f5c\u662f\u5426\u6210\u529f\uff0c\u5e76\u83b7\u53d6\u6240\u5f71\u54cd\u7684\u884c\u6570\u3002 \u4ee5\u4e0a\u5c31\u662fJDBC \u4e2d\u7684 executeQuery \u548c executeUpdate \u65b9\u6cd5\uff1a\u5b83\u4eec\u7684\u662f\u4ec0\u4e48\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/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-7053","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7053","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=7053"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7053\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=7053"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=7053"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=7053"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}