{"id":1871,"date":"2022-11-28T21:37:11","date_gmt":"2022-11-28T13:37:11","guid":{"rendered":"https:\/\/qaqaq.top\/?p=1871"},"modified":"2022-11-28T21:41:01","modified_gmt":"2022-11-28T13:41:01","slug":"c3p0%e6%95%b0%e6%8d%ae%e5%ba%93%e8%bf%9e%e6%8e%a5%e6%b1%a0%e7%9a%84%e4%b8%a4%e7%a7%8d%e5%ae%9e%e7%8e%b0%e6%96%b9%e5%bc%8f","status":"publish","type":"post","link":"https:\/\/qaqaq.top\/?p=1871","title":{"rendered":"C3P0\u6570\u636e\u5e93\u8fde\u63a5\u6c60\u7684\u4e24\u79cd\u5b9e\u73b0\u65b9\u5f0f"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>package top.qaqaq.P47.connection;\n\nimport java.beans.PropertyVetoException;\nimport java.sql.Connection;\nimport java.sql.SQLException;\n\nimport org.junit.Test;\n\nimport com.mchange.v2.c3p0.ComboPooledDataSource;\nimport com.mchange.v2.c3p0.DataSources;\n\npublic class C3P0Test {\n\n\t\/\/\u65b9\u5f0f\u4e00\uff1a\n\t@Test\n\tpublic void testGetConnection() throws Exception {\n\t\t\/\/\u83b7\u53d6c3p0\u6570\u636e\u5e93\u8fde\u63a5\u6c60\n\t\tComboPooledDataSource cpds = new ComboPooledDataSource();\n\t\tcpds.setDriverClass(\"com.mysql.cj.jdbc.Driver\");\n\t\tcpds.setJdbcUrl(\"jdbc:mysql:\/\/localhost:3306\/test\");\n\t\tcpds.setUser(\"root\");\n\t\tcpds.setPassword(\"123456\");\n\t\t\/\/\u901a\u8fc7\u8bbe\u7f6e\u76f8\u5173\u7684\u53c2\u6570\uff0c\u5bf9\u6570\u636e\u5e93\u8fde\u63a5\u6c60\u8fdb\u884c\u7ba1\u7406\uff1a\n\t\t\/\/\u8bbe\u7f6e\u521d\u59cb\u65f6\u6570\u636e\u5e93\u8fde\u63a5\u6c60\u4e2d\u7684\u8fde\u63a5\u6570\n\t\tcpds.setInitialPoolSize(10);\n\t\t\n\t\tConnection conn = cpds.getConnection();\n\t\tSystem.out.println(conn);\n\t\t\n\t\t\/\/v0.9.1.2 \u9500\u6bc1c3p0\u6570\u636e\u5e93\u8fde\u63a5\u6c60\n\t\tDataSources.destroy(cpds);\n\t\t\n\t\t\/\/v0.9.5.5 \u9500\u6bc1c3p0\u6570\u636e\u5e93\u8fde\u63a5\u6c60\n\t\tcpds.close();\n\t}\n\t\n\t\/\/\u65b9\u5f0f\u4e8c\uff1a\u4f7f\u7528\u914d\u7f6e\u6587\u4ef6\n\t@Test\n\tpublic void testGetConnection1() throws SQLException {\n\t\t\n\t\tComboPooledDataSource cpds = new ComboPooledDataSource(\"helloc3p0\");  \n\t\tConnection conn = cpds.getConnection();\n\t\tSystem.out.println(conn);\n\t\t\n\t}\n}\n<\/code><\/pre>\n\n\n\n<p>c3p0-config.xml<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?>\n&lt;c3p0-config>\n\n\t&lt;named-config name=\"helloc3p0\">\n\t\t&lt;!-- \u63d0\u4f9b\u83b7\u53d6\u8fde\u63a5\u76844\u4e2a\u57fa\u672c\u4fe1\u606f -->>\n\t\t&lt;property name=\"driverClass\">com.mysql.cj.jdbc.Driver&lt;\/property>\n\t\t&lt;property name=\"jdbcUrl\">jdbc:mysql:\/\/\/test&lt;\/property>\n\t\t&lt;property name=\"user\">root&lt;\/property>\n\t\t&lt;property name=\"password\">123456&lt;\/property>\n\t\t\n\t\t&lt;!-- \u8fdb\u884c\u6570\u636e\u5e93\u8fde\u63a5\u6c60\u7ba1\u7406\u7684\u57fa\u672c\u4fe1\u606f -->>\n\t\t&lt;!-- \u5f53\u6570\u636e\u5e93\u8fde\u63a5\u6c60\u4e2d\u7684\u8fde\u63a5\u6570\u4e0d\u591f\u65f6\uff0cc3p0\u4e00\u6b21\u6027\u5411\u6570\u636e\u5e93\u670d\u52a1\u5668\u7533\u8bf7\u7684\u8fde\u63a5\u6570 -->>\n\t\t&lt;property name=\"acquireIncrement\">5&lt;\/property>\n\t\t&lt;!-- c3p0\u6570\u636e\u5e93\u8fde\u63a5\u6c60\u4e2d\u521d\u59cb\u5316\u65f6\u7684\u8fde\u63a5\u6570 -->>\n\t\t&lt;property name=\"initialPoolSize\">10&lt;\/property>\n\t\t&lt;!-- c3p0\u6570\u636e\u5e93\u8fde\u63a5\u6c60\u7ef4\u62a4\u7684\u6700\u5c11\u7684\u8fde\u63a5\u6570 -->>\n\t\t&lt;property name=\"minPoolSize\">10&lt;\/property>\n\t\t&lt;!-- c3p0\u6570\u636e\u5e93\u8fde\u63a5\u6c60\u7ef4\u62a4\u7684\u6700\u591a\u7684\u8fde\u63a5\u6570 -->>\n\t\t&lt;property name=\"maxPoolSize\">100&lt;\/property>\n\t\t&lt;!-- c3p0\u6570\u636e\u5e93\u8fde\u63a5\u6c60\u6700\u591a\u7ef4\u62a4\u7684Statement\u7684\u4e2a\u6570 -->>\n\t\t&lt;property name=\"maxStatements\">50&lt;\/property>\n\t\t&lt;!-- \u6bcf\u4e2a\u8fde\u63a5\u4e2d\u53ef\u4ee5\u6700\u591a\u4f7f\u7528\u7684Statement\u7684\u4e2a\u6570 -->>\n\t\t&lt;property name=\"maxStatementsPerConnection\">2&lt;\/property>\n\n\t&lt;\/named-config>\n&lt;\/c3p0-config><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>c3p0-config.xml<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[38],"tags":[48],"class_list":["post-1871","post","type-post","status-publish","format-standard","hentry","category-jdbc-code","tag-jdbc"],"_links":{"self":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/1871"}],"collection":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1871"}],"version-history":[{"count":3,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/1871\/revisions"}],"predecessor-version":[{"id":1880,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/1871\/revisions\/1880"}],"wp:attachment":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1871"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1871"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1871"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}