{"id":168741,"date":"2024-11-06T15:45:19","date_gmt":"2024-11-06T07:45:19","guid":{"rendered":"https:\/\/server.hk\/cnblog\/168741\/"},"modified":"2024-11-06T15:45:20","modified_gmt":"2024-11-06T07:45:20","slug":"tomcatsql-server2000-%e9%80%a3%e6%8e%a5%e6%b1%a0%e7%9a%84%e6%ad%a3%e7%a2%ba%e9%85%8d%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/168741\/","title":{"rendered":"Tomcat+SQL Server2000 \u9023\u63a5\u6c60\u7684\u6b63\u78ba\u914d\u7f6e"},"content":{"rendered":"<h1 id=\"tomcatsql-server2000-%e9%80%a3%e6%8e%a5%e6%b1%a0%e7%9a%84%e6%ad%a3%e7%a2%ba%e9%85%8d%e7%bd%ae-UtQAJfIxQg\">Tomcat+SQL Server2000 \u9023\u63a5\u6c60\u7684\u6b63\u78ba\u914d\u7f6e<\/h1>\n<p>\u5728\u73fe\u4ee3\u7684\u7db2\u7d61\u61c9\u7528\u4e2d\uff0c\u9023\u63a5\u6c60\u6280\u8853\u5df2\u6210\u70ba\u63d0\u9ad8\u6578\u64da\u5eab\u6027\u80fd\u7684\u91cd\u8981\u624b\u6bb5\u3002\u5c0d\u65bc\u4f7f\u7528 Java \u7684 Tomcat \u4f3a\u670d\u5668\u548c SQL Server 2000 \u6578\u64da\u5eab\u7684\u958b\u767c\u8005\u4f86\u8aaa\uff0c\u6b63\u78ba\u914d\u7f6e\u9023\u63a5\u6c60\u4e0d\u50c5\u80fd\u5920\u63d0\u5347\u61c9\u7528\u7684\u97ff\u61c9\u901f\u5ea6\uff0c\u9084\u80fd\u6709\u6548\u7ba1\u7406\u8cc7\u6e90\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e\u5982\u4f55\u5728 Tomcat \u4e2d\u6b63\u78ba\u914d\u7f6e SQL Server 2000 \u7684\u9023\u63a5\u6c60\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af%e9%80%a3%e6%8e%a5%e6%b1%a0%ef%bc%9f-UtQAJfIxQg\">\u4ec0\u9ebc\u662f\u9023\u63a5\u6c60\uff1f<\/h2>\n<p>\u9023\u63a5\u6c60\u662f\u4e00\u7a2e\u7528\u65bc\u7ba1\u7406\u6578\u64da\u5eab\u9023\u63a5\u7684\u6280\u8853\uff0c\u5b83\u901a\u904e\u91cd\u7528\u5df2\u5efa\u7acb\u7684\u9023\u63a5\u4f86\u6e1b\u5c11\u9023\u63a5\u7684\u958b\u92b7\u3002\u7576\u61c9\u7528\u7a0b\u5e8f\u9700\u8981\u8a2a\u554f\u6578\u64da\u5eab\u6642\uff0c\u5b83\u53ef\u4ee5\u5f9e\u9023\u63a5\u6c60\u4e2d\u7372\u53d6\u4e00\u500b\u53ef\u7528\u7684\u9023\u63a5\uff0c\u800c\u4e0d\u662f\u6bcf\u6b21\u90fd\u5275\u5efa\u65b0\u7684\u9023\u63a5\u3002\u9019\u6a23\u4e0d\u50c5\u63d0\u9ad8\u4e86\u6027\u80fd\uff0c\u9084\u6e1b\u5c11\u4e86\u6578\u64da\u5eab\u7684\u8ca0\u64d4\u3002<\/p>\n<h2 id=\"tomcat-%e4%b8%ad%e7%9a%84%e9%80%a3%e6%8e%a5%e6%b1%a0%e9%85%8d%e7%bd%ae-UtQAJfIxQg\">Tomcat \u4e2d\u7684\u9023\u63a5\u6c60\u914d\u7f6e<\/h2>\n<p>\u5728 Tomcat \u4e2d\uff0c\u6700\u5e38\u7528\u7684\u9023\u63a5\u6c60\u662f Apache DBCP\uff08Database Connection Pooling\uff09\u3002\u4ee5\u4e0b\u662f\u914d\u7f6e SQL Server 2000 \u9023\u63a5\u6c60\u7684\u6b65\u9a5f\uff1a<\/p>\n<h3 id=\"1-%e6%b7%bb%e5%8a%a0-jdbc-%e9%a9%85%e5%8b%95-UtQAJfIxQg\">1. \u6dfb\u52a0 JDBC \u9a45\u52d5<\/h3>\n<p>\u9996\u5148\uff0c\u60a8\u9700\u8981\u4e0b\u8f09 SQL Server 2000 \u7684 JDBC \u9a45\u52d5\u7a0b\u5e8f\uff0c\u901a\u5e38\u662f <code>sqljdbc.jar<\/code> \u6587\u4ef6\u3002\u5c07\u6b64\u6587\u4ef6\u653e\u7f6e\u5728 Tomcat \u7684 <code>lib<\/code> \u76ee\u9304\u4e2d\uff0c\u4ee5\u4fbf Tomcat \u80fd\u5920\u627e\u5230\u5b83\u3002<\/p>\n<h3 id=\"2-%e9%85%8d%e7%bd%ae-context-xml-UtQAJfIxQg\">2. \u914d\u7f6e context.xml<\/h3>\n<p>\u63a5\u4e0b\u4f86\uff0c\u60a8\u9700\u8981\u5728 Tomcat \u7684 <code>conf\/context.xml<\/code> \u6587\u4ef6\u4e2d\u6dfb\u52a0\u6578\u64da\u6e90\u914d\u7f6e\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u793a\u4f8b\u914d\u7f6e\uff1a<\/p>\n<pre><code>&lt;Context&gt;\n    &lt;Resource name=\"jdbc\/MyDB\"\n              auth=\"Container\"\n              type=\"javax.sql.DataSource\"\n              maxActive=\"100\"\n              maxIdle=\"30\"\n              maxWait=\"10000\"\n              username=\"yourUsername\"\n              password=\"yourPassword\"\n              driverClassName=\"com.microsoft.sqlserver.jdbc.SQLServerDriver\"\n              url=\"jdbc:sqlserver:\/\/localhost:1433;databaseName=yourDatabaseName;\"\/&gt;\n&lt;\/Context&gt;<\/code><\/pre>\n<p>\u5728\u9019\u6bb5\u914d\u7f6e\u4e2d\uff0c\u60a8\u9700\u8981\u6839\u64da\u5be6\u969b\u60c5\u6cc1\u66ff\u63db\u4ee5\u4e0b\u53c3\u6578\uff1a<\/p>\n<ul>\n<li><code>yourUsername<\/code>\uff1a\u6578\u64da\u5eab\u7528\u6236\u540d<\/li>\n<li><code>yourPassword<\/code>\uff1a\u6578\u64da\u5eab\u5bc6\u78bc<\/li>\n<li><code>yourDatabaseName<\/code>\uff1a\u6578\u64da\u5eab\u540d\u7a31<\/li>\n<\/ul>\n<h3 id=\"3-%e5%9c%a8-web-xml-%e4%b8%ad%e5%bc%95%e7%94%a8%e6%95%b8%e6%93%9a%e6%ba%90-UtQAJfIxQg\">3. \u5728 web.xml \u4e2d\u5f15\u7528\u6578\u64da\u6e90<\/h3>\n<p>\u5728\u60a8\u7684\u61c9\u7528\u7a0b\u5e8f\u7684 <code>WEB-INF\/web.xml<\/code> \u6587\u4ef6\u4e2d\uff0c\u60a8\u9700\u8981\u5f15\u7528\u525b\u624d\u914d\u7f6e\u7684\u6578\u64da\u6e90\uff1a<\/p>\n<pre><code>&lt;resource-ref&gt;\n    &lt;description&gt;DB Connection&lt;\/description&gt;\n    &lt;res-ref-name&gt;jdbc\/MyDB&lt;\/res-ref-name&gt;\n    &lt;res-type&gt;javax.sql.DataSource&lt;\/res-type&gt;\n    &lt;res-link&gt;jdbc\/MyDB&lt;\/res-link&gt;\n&lt;\/resource-ref&gt;<\/code><\/pre>\n<h2 id=\"%e9%80%a3%e6%8e%a5%e6%b1%a0%e7%9a%84%e6%80%a7%e8%83%bd%e8%aa%bf%e6%95%b4-UtQAJfIxQg\">\u9023\u63a5\u6c60\u7684\u6027\u80fd\u8abf\u6574<\/h2>\n<p>\u5728\u914d\u7f6e\u5b8c\u6210\u5f8c\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u6839\u64da\u5be6\u969b\u7684\u61c9\u7528\u9700\u6c42\u9032\u884c\u6027\u80fd\u8abf\u6574\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5efa\u8b70\uff1a<\/p>\n<ul>\n<li><strong>maxActive<\/strong>\uff1a\u6839\u64da\u61c9\u7528\u7684\u4e26\u767c\u9700\u6c42\u8abf\u6574\u6700\u5927\u6d3b\u52d5\u9023\u63a5\u6578\u3002<\/li>\n<li><strong>maxIdle<\/strong>\uff1a\u8a2d\u7f6e\u6700\u5927\u7a7a\u9592\u9023\u63a5\u6578\uff0c\u4ee5\u907f\u514d\u8cc7\u6e90\u6d6a\u8cbb\u3002<\/li>\n<li><strong>maxWait<\/strong>\uff1a\u8a2d\u7f6e\u7372\u53d6\u9023\u63a5\u7684\u6700\u5927\u7b49\u5f85\u6642\u9593\uff0c\u907f\u514d\u61c9\u7528\u56e0\u7b49\u5f85\u9023\u63a5\u800c\u9020\u6210\u7684\u6027\u80fd\u74f6\u9838\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-UtQAJfIxQg\">\u7e3d\u7d50<\/h2>\n<p>\u6b63\u78ba\u914d\u7f6e Tomcat \u8207 SQL Server 2000 \u7684\u9023\u63a5\u6c60\u5c0d\u65bc\u63d0\u5347\u61c9\u7528\u6027\u80fd\u81f3\u95dc\u91cd\u8981\u3002\u901a\u904e\u5408\u7406\u7684\u914d\u7f6e\u548c\u8abf\u6574\uff0c\u60a8\u53ef\u4ee5\u6709\u6548\u7ba1\u7406\u6578\u64da\u5eab\u9023\u63a5\uff0c\u5f9e\u800c\u63d0\u9ad8\u61c9\u7528\u7684\u97ff\u61c9\u901f\u5ea6\u548c\u7a69\u5b9a\u6027\u3002\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u9069\u5408\u5404\u985e\u578b\u7684\u61c9\u7528\u9700\u6c42\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3\u5982\u4f55\u6b63\u78ba\u914d\u7f6eTomcat\u8207SQL Server 2000\u7684\u9023\u63a5\u6c60\uff0c\u63d0\u5347\u61c9\u7528\u6027\u80fd\u8207\u8cc7\u6e90\u7ba1\u7406\u6548\u7387\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-168741","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/168741","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=168741"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/168741\/revisions"}],"predecessor-version":[{"id":168742,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/168741\/revisions\/168742"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=168741"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=168741"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=168741"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}