{"id":26110,"date":"2024-11-24T11:05:32","date_gmt":"2024-11-24T03:05:32","guid":{"rendered":"https:\/\/fwq.ai\/blog\/26110\/"},"modified":"2024-11-24T11:05:32","modified_gmt":"2024-11-24T03:05:32","slug":"mysql-%e4%be%9d%e8%b5%96%e4%b8%ba%e4%bd%95%e8%ae%be%e5%ae%9a%e4%b8%ba%e8%bf%90%e8%a1%8c%e6%97%b6%e8%8c%83%e5%9b%b4%e8%80%8c%e9%9d%9e%e7%bc%96%e8%af%91%e6%97%b6%e8%8c%83%e5%9b%b4%ef%bc%9f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/26110\/","title":{"rendered":"MySQL \u4f9d\u8d56\u4e3a\u4f55\u8bbe\u5b9a\u4e3a\u8fd0\u884c\u65f6\u8303\u56f4\u800c\u975e\u7f16\u8bd1\u65f6\u8303\u56f4\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173080252888953.jpg\" class=\"aligncenter\" title=\"MySQL \u4f9d\u8d56\u4e3a\u4f55\u8bbe\u5b9a\u4e3a\u8fd0\u884c\u65f6\u8303\u56f4\u800c\u975e\u7f16\u8bd1\u65f6\u8303\u56f4\uff1f\u63d2\u56fe\" alt=\"MySQL \u4f9d\u8d56\u4e3a\u4f55\u8bbe\u5b9a\u4e3a\u8fd0\u884c\u65f6\u8303\u56f4\u800c\u975e\u7f16\u8bd1\u65f6\u8303\u56f4\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong> \u4f9d\u8d56\u4e3a\u4f55\u8bbe\u5b9a\u4e3a\u8fd0\u884c\u65f6\u8303\u56f4\uff1f<\/strong><\/p>\n<p>\u95ee\u9898\uff1amysql \u4f9d\u8d56\u7684\u8303\u56f4\u4e3a\u4ec0\u4e48\u8bbe\u5b9a\u4e3a\u8fd0\u884c\u65f6\uff0c\u800c\u4e0d\u662f\u7f16\u8bd1\u65f6\uff1f\u5982\u679c\u6253\u5305\u65f6\u4e0d\u5305\u542b mysql \u4f9d\u8d56\uff0c\u90a3\u4e48\u53d1\u5e03\u540e\u7684\u9879\u76ee\u5982\u4f55\u8fde\u63a5\u6570\u636e\u5e93\uff1f<\/p>\n<p>\u56de\u7b54\uff1a<\/p>\n<p>jdbc \u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u7f16\u7801\u65f6\u53ea\u4f9d\u8d56\u4e8e jdbc \u63a5\u53e3\uff0c\u800c\u4e0d\u76f4\u63a5\u4f9d\u8d56\u4e8e mysql jdbc \u9a71\u52a8\u3002\u5728\u8fde\u63a5 mysql \u65f6\uff0c\u6211\u4eec\u4f1a\u4f7f\u7528\u7c7b\u4f3c\u4ee5\u4e0b\u7684\u4ee3\u7801\uff1a<\/p>\n<pre>Class.forName(\"com.mysql.jdbc.Driver\");\nConnection conn = DriverManager.getConnection(url, username, password);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6211\u4eec\u5c06\u4f7f\u7528\u53cd\u5c04\u65b9\u6cd5 class.forname \u5728\u8fd0\u884c\u65f6\u4ece\u7c7b\u8def\u5f84\u4e2d\u52a0\u8f7d mysql jdbc \u9a71\u52a8\uff0c\u540e\u7eed\u8c03\u7528\u65f6\u6ca1\u6709\u4efb\u4f55\u4f7f\u7528 mysql jdbc \u7279\u5b9a\u65b9\u6cd5\uff0c\u800c\u662f\u4f7f\u7528 jdbc \u63a5\u53e3\u3002<\/p>\n<p>\u56e0\u6b64\uff0cjdbc \u9a71\u52a8\u4e0d\u662f\u7f16\u8bd1\u4f9d\u8d56\uff08compile scope\uff09\uff0c\u56e0\u4e3a\u6211\u4eec\u7684\u4ee3\u7801\u6ca1\u6709\u76f4\u63a5\u4f7f\u7528 jdbc \u9a71\u52a8\u7684\u7279\u5b9a\u65b9\u6cd5\uff0c\u6240\u4ee5\u7f16\u8bd1\u65f6\u4e0d\u9700\u8981\u52a0\u8f7d jdbc \u9a71\u52a8\u3002jdbc \u63a5\u53e3\u624d\u662f\u7f16\u8bd1\u4f9d\u8d56\uff0c\u800c jdbc \u9a71\u52a8\u5c5e\u4e8e\u8fd0\u884c\u4f9d\u8d56\uff08runtime scope\uff09\u3002<\/p>\n<p>\u5728\u58f0\u660e\u8fd0\u884c\u4f9d\u8d56\u65f6\uff0c\u4e0d\u4f1a\u5728\u7f16\u8bd1\u8fc7\u7a0b\u4e2d\u5c06\u4f9d\u8d56\u6dfb\u52a0\u5230\u7c7b\u8def\u5f84\u4e2d\uff0c\u4f46\u4f1a\u5728\u6253\u5305\u65f6\u5c06\u5176\u52a0\u5165\u3002\u56e0\u6b64\uff0c\u65e0\u9700\u62c5\u5fc3\uff0cjdbc \u9a71\u52a8\u5e94\u8be5\u8bbe\u5b9a\u4e3a\u8fd0\u884c\u65f6\u4f9d\u8d56\u3002<\/p>\n<p>\u7f16\u8bd1\u4f9d\u8d56\u6307\u7684\u662f\u7f16\u8bd1\u65f6\u9700\u8981\u8be5\u4f9d\u8d56\uff0c\u901a\u5e38\u7f16\u8bd1\u4f9d\u8d56\u4e5f\u662f\u8fd0\u884c\u4f9d\u8d56\u3002\u53e6\u4e00\u65b9\u9762\uff0cmaven\/gradle \u4e2d\u7684\u7f16\u8bd1\u4f9d\u8d56\u901a\u5e38\u5728\u7f16\u8bd1\u540e\u4e5f\u5305\u542b\u5728 fat jar \u4e2d\uff0c\u8fd9\u610f\u5473\u7740\u7f16\u8bd1\u4f9d\u8d56\u9690\u542b\u5305\u542b\u4e86\u8fd0\u884c\u4f9d\u8d56\u3002\u4e0d\u8fc7\uff0c\u67d0\u4e9b\u4f9d\u8d56\u4e5f\u53ef\u80fd\u662f compileonly \u4f9d\u8d56\uff0c\u4f8b\u5982\u7528\u4e8e\u5904\u7406\u6ce8\u91ca\u7684\uff0c\u5b83\u4eec\u4ec5\u5728\u7f16\u8bd1\u65f6\u9700\u8981\uff0c\u5728\u8fd0\u884c\u65f6\u4e0d\u9700\u8981\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fMySQL \u4f9d\u8d56\u4e3a\u4f55\u8bbe\u5b9a\u4e3a\u8fd0\u884c\u65f6\u8303\u56f4\u800c\u975e\u7f16\u8bd1\u65f6\u8303\u56f4\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f9d\u8d56\u4e3a\u4f55\u8bbe\u5b9a\u4e3a\u8fd0\u884c\u65f6\u8303\u56f4\uff1f \u95ee\u9898\uff1amysql \u4f9d\u8d56\u7684\u8303\u56f4\u4e3a\u4ec0\u4e48\u8bbe\u5b9a\u4e3a\u8fd0\u884c\u65f6\uff0c\u800c\u4e0d\u662f\u7f16\u8bd1\u65f6\uff1f\u5982\u679c\u6253\u5305\u65f6\u4e0d\u5305\u542b mysql \u4f9d\u8d56\uff0c\u90a3\u4e48\u53d1\u5e03\u540e\u7684\u9879\u76ee\u5982\u4f55\u8fde\u63a5\u6570\u636e\u5e93\uff1f \u56de\u7b54\uff1a jdbc \u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u7f16\u7801\u65f6\u53ea\u4f9d\u8d56\u4e8e jdbc \u63a5\u53e3\uff0c\u800c\u4e0d\u76f4\u63a5\u4f9d\u8d56\u4e8e mysql jdbc \u9a71\u52a8\u3002\u5728\u8fde\u63a5 mysql \u65f6\uff0c\u6211\u4eec\u4f1a\u4f7f\u7528\u7c7b\u4f3c\u4ee5\u4e0b\u7684\u4ee3\u7801\uff1a Class.forName(&#8220;com.mysql.jdbc.Driver&#8221;); Connection conn = DriverManager.getConnection(url, username, password); \u767b\u5f55\u540e\u590d\u5236 \u6211\u4eec\u5c06\u4f7f\u7528\u53cd\u5c04\u65b9\u6cd5 class.forname \u5728\u8fd0\u884c\u65f6\u4ece\u7c7b\u8def\u5f84\u4e2d\u52a0\u8f7d mysql jdbc \u9a71\u52a8\uff0c\u540e\u7eed\u8c03\u7528\u65f6\u6ca1\u6709\u4efb\u4f55\u4f7f\u7528 mysql jdbc \u7279\u5b9a\u65b9\u6cd5\uff0c\u800c\u662f\u4f7f\u7528 jdbc \u63a5\u53e3\u3002 \u56e0\u6b64\uff0cjdbc \u9a71\u52a8\u4e0d\u662f\u7f16\u8bd1\u4f9d\u8d56\uff08compile scope\uff09\uff0c\u56e0\u4e3a\u6211\u4eec\u7684\u4ee3\u7801\u6ca1\u6709\u76f4\u63a5\u4f7f\u7528 jdbc \u9a71\u52a8\u7684\u7279\u5b9a\u65b9\u6cd5\uff0c\u6240\u4ee5\u7f16\u8bd1\u65f6\u4e0d\u9700\u8981\u52a0\u8f7d jdbc \u9a71\u52a8\u3002jdbc \u63a5\u53e3\u624d\u662f\u7f16\u8bd1\u4f9d\u8d56\uff0c\u800c jdbc \u9a71\u52a8\u5c5e\u4e8e\u8fd0\u884c\u4f9d\u8d56\uff08runtime scope\uff09\u3002 \u5728\u58f0\u660e\u8fd0\u884c\u4f9d\u8d56\u65f6\uff0c\u4e0d\u4f1a\u5728\u7f16\u8bd1\u8fc7\u7a0b\u4e2d\u5c06\u4f9d\u8d56\u6dfb\u52a0\u5230\u7c7b\u8def\u5f84\u4e2d\uff0c\u4f46\u4f1a\u5728\u6253\u5305\u65f6\u5c06\u5176\u52a0\u5165\u3002\u56e0\u6b64\uff0c\u65e0\u9700\u62c5\u5fc3\uff0cjdbc \u9a71\u52a8\u5e94\u8be5\u8bbe\u5b9a\u4e3a\u8fd0\u884c\u65f6\u4f9d\u8d56\u3002 \u7f16\u8bd1\u4f9d\u8d56\u6307\u7684\u662f\u7f16\u8bd1\u65f6\u9700\u8981\u8be5\u4f9d\u8d56\uff0c\u901a\u5e38\u7f16\u8bd1\u4f9d\u8d56\u4e5f\u662f\u8fd0\u884c\u4f9d\u8d56\u3002\u53e6\u4e00\u65b9\u9762\uff0cmaven\/gradle \u4e2d\u7684\u7f16\u8bd1\u4f9d\u8d56\u901a\u5e38\u5728\u7f16\u8bd1\u540e\u4e5f\u5305\u542b\u5728 fat jar \u4e2d\uff0c\u8fd9\u610f\u5473\u7740\u7f16\u8bd1\u4f9d\u8d56\u9690\u542b\u5305\u542b\u4e86\u8fd0\u884c\u4f9d\u8d56\u3002\u4e0d\u8fc7\uff0c\u67d0\u4e9b\u4f9d\u8d56\u4e5f\u53ef\u80fd\u662f compileonly \u4f9d\u8d56\uff0c\u4f8b\u5982\u7528\u4e8e\u5904\u7406\u6ce8\u91ca\u7684\uff0c\u5b83\u4eec\u4ec5\u5728\u7f16\u8bd1\u65f6\u9700\u8981\uff0c\u5728\u8fd0\u884c\u65f6\u4e0d\u9700\u8981\u3002 \u4ee5\u4e0a\u5c31\u662fMySQL [&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-26110","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26110","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=26110"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26110\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=26110"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=26110"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=26110"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}