<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>漫步 &#187; tomcat</title>
	<atom:link href="http://roamlog.info/tag/tomcat/feed" rel="self" type="application/rss+xml" />
	<link>http://roamlog.info</link>
	<description>WordPress, Design, Web2.0, Software, IT, News</description>
	<lastBuildDate>Thu, 29 Dec 2011 11:05:33 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>tomcat5.5.23中access连接池的配置方法</title>
		<link>http://roamlog.info/archives/connect-pool-of-access.html</link>
		<comments>http://roamlog.info/archives/connect-pool-of-access.html#comments</comments>
		<pubDate>Thu, 17 May 2007 05:10:51 +0000</pubDate>
		<dc:creator>漫步</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[access]]></category>
		<category><![CDATA[tomcat]]></category>

		<guid isPermaLink="false">http://roamlog.cn/index.php/2007/05/17/connect-pool-of-access/</guid>
		<description><![CDATA[记录一下, 这里只给出server.xml的配置方法,其它的配置及测试代码在  这里

&#60;logger className=&#34;org.apache.catalina.logger.FileLogger&#34;
            directory=&#34;logs&#34;  prefix=&#34;localhost_log.&#34; suffix=&#34;.txt&#34;
            timestamp=&#34;true&#34;/&#62;
         &#60;context docBase=&#34;cmmi&#34; path=&#34;/cmmi&#34; 
            [...]]]></description>
			<content:encoded><![CDATA[<p>记录一下, 这里只给出server.xml的配置方法,其它的配置及测试代码在  <a href="http://roamlog.cn/?p=39">这里</a></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;logger</span> <span style="color: #000066;">className</span>=<span style="color: #ff0000;">&quot;org.apache.catalina.logger.FileLogger&quot;</span></span>
<span style="color: #009900;">            <span style="color: #000066;">directory</span>=<span style="color: #ff0000;">&quot;logs&quot;</span>  <span style="color: #000066;">prefix</span>=<span style="color: #ff0000;">&quot;localhost_log.&quot;</span> <span style="color: #000066;">suffix</span>=<span style="color: #ff0000;">&quot;.txt&quot;</span></span>
<span style="color: #009900;">            <span style="color: #000066;">timestamp</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;context</span> <span style="color: #000066;">docBase</span>=<span style="color: #ff0000;">&quot;cmmi&quot;</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;/cmmi&quot;</span> </span>
<span style="color: #009900;">                 <span style="color: #000066;">reloadable</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">crossContext</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;logger</span> <span style="color: #000066;">className</span>=<span style="color: #ff0000;">&quot;org.apache.catalina.logger.FileLogger&quot;</span></span>
<span style="color: #009900;">                     <span style="color: #000066;">prefix</span>=<span style="color: #ff0000;">&quot;localhost_lovehome_log.&quot;</span> </span>
<span style="color: #009900;">                     <span style="color: #000066;">suffix</span>=<span style="color: #ff0000;">&quot;.txt&quot;</span> <span style="color: #000066;">timestamp</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resource</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;jdbc/access&quot;</span> <span style="color: #000066;">auth</span>=<span style="color: #ff0000;">&quot;Container&quot;</span> </span>
<span style="color: #009900;">              <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;javax.sql.DataSource&quot;</span></span>
<span style="color: #009900;">              <span style="color: #000066;">maxActive</span>=<span style="color: #ff0000;">&quot;100&quot;</span> <span style="color: #000066;">maxIdle</span>=<span style="color: #ff0000;">&quot;30&quot;</span> <span style="color: #000066;">maxWait</span>=<span style="color: #ff0000;">&quot;10000&quot;</span></span>
<span style="color: #009900;">              <span style="color: #000066;">driverClassName</span>=<span style="color: #ff0000;">&quot;sun.jdbc.odbc.JdbcOdbcDriver&quot;</span></span>
<span style="color: #009900;">              <span style="color: #000066;">username</span>=<span style="color: #ff0000;">&quot;sa&quot;</span> <span style="color: #000066;">password</span>=<span style="color: #ff0000;">&quot;12345&quot;</span></span>
<span style="color: #009900;">              <span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;jdbc:odbc:work&quot;</span></span>
<span style="color: #009900;">              <span style="color: #000066;">defaultAutoCommit</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">removeAbondoned</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #009900;">              <span style="color: #000066;">removeAbondonedTimeout</span>=<span style="color: #ff0000;">&quot;60&quot;</span> <span style="color: #000066;">logAbondoned</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/context<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<img src="http://roamlog.info/?ak_action=api_record_view&id=33&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roamlog.info/archives/connect-pool-of-access.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>一个简单的jsp分页实现</title>
		<link>http://roamlog.info/archives/simpleness-pagination-of-jsp.html</link>
		<comments>http://roamlog.info/archives/simpleness-pagination-of-jsp.html#comments</comments>
		<pubDate>Thu, 29 Mar 2007 00:54:15 +0000</pubDate>
		<dc:creator>漫步</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[jsp]]></category>
		<category><![CDATA[tomcat]]></category>

		<guid isPermaLink="false">http://roamlog.cn/index.php/2007/03/29/simpleness-pagination-of-jsp/</guid>
		<description><![CDATA[环境
xp + jdk1.5 + tomcat5.5.23 + eclipse3.2.2 + myeclipse5.1.1GA + sqlserver2000
使用连接池方式连接数据库,至于这方面的问题可参考 http://roamlog.cn/?p=39
写一个DBConnection.java封装对数据库的一些操作,实现SqlTestDS的getConnection()方法连接数据库
DBConnection.java

package database;
import java.sql.*;
public class DBConnection&#123;
	private Connection conn = null;
	private Statement stmt = null;
	ResultSet rs = null;
	public ResultSet executeQuery&#40;String sql&#41; &#123;
	try &#123;
	     conn =SqlTestDS.getConnection&#40;&#41;;
             stmt=conn.createStatement
&#40;ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY&#41;;
			rs = stmt.executeQuery&#40;sql&#41;;
		&#125; catch &#40;Exception [...]]]></description>
			<content:encoded><![CDATA[<p>环境<br />
xp + jdk1.5 + tomcat5.5.23 + eclipse3.2.2 + myeclipse5.1.1GA + sqlserver2000</p>
<p>使用连接池方式连接数据库,至于这方面的问题可参考 http://roamlog.cn/?p=39</p>
<p>写一个DBConnection.java封装对数据库的一些操作,实现SqlTestDS的getConnection()方法连接数据库</p>
<p>DBConnection.java</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">database</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.sql.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> DBConnection<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Connection</span> conn <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Statement</span> stmt <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #003399;">ResultSet</span> rs <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">ResultSet</span> executeQuery<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> sql<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
	     conn <span style="color: #339933;">=</span>SqlTestDS.<span style="color: #006633;">getConnection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
             stmt<span style="color: #339933;">=</span>conn.<span style="color: #006633;">createStatement</span>
<span style="color: #009900;">&#40;</span><span style="color: #003399;">ResultSet</span>.<span style="color: #006633;">TYPE_SCROLL_INSENSITIVE</span>,
<span style="color: #003399;">ResultSet</span>.<span style="color: #006633;">CONCUR_READ_ONLY</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			rs <span style="color: #339933;">=</span> stmt.<span style="color: #006633;">executeQuery</span><span style="color: #009900;">&#40;</span>sql<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">return</span> rs<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> executeUpdate<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> sql<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			conn <span style="color: #339933;">=</span> SqlTestDS.<span style="color: #006633;">getConnection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			stmt <span style="color: #339933;">=</span>conn.<span style="color: #006633;">createStatement</span>
<span style="color: #009900;">&#40;</span><span style="color: #003399;">ResultSet</span>.<span style="color: #006633;">TYPE_SCROLL_INSENSITIVE</span>,
<span style="color: #003399;">ResultSet</span>.<span style="color: #006633;">CONCUR_READ_ONLY</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			stmt.<span style="color: #006633;">executeUpdate</span><span style="color: #009900;">&#40;</span>sql<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> closeStmt<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			stmt.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> closeConn<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			conn.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><span id="more-29"></span><br />
一个jsp文件,负责分页的处理<br />
fenye.jsp</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;%@ page contentType=&quot;text/html;charset=gbk&quot;%&gt;
&lt;%@ page pageEncoding=&quot;gbk&quot;%&gt;
&lt;%
request.setCharacterEncoding(&quot;gbk&quot;);
%&gt;
&lt;%@ page import=&quot;java.sql.*&quot;%&gt;
&lt;%@ page import=&quot;database.DBConn&quot;%&gt;
&nbsp;
&lt;%
	//变量声明
	ResultSet sqlRst; //结果集对象
	String strCon; //数据库连接字符串
	String strSQL; //SQL语句
	int intPageSize; //一页显示的记录数
	int intRowCount; //记录总数
	int intPageCount; //总页数
	int intPage; //待显示页码
	String strPage;
	int i;
	//设置一页显示的记录数
	intPageSize = 4;
	//取得待显示页码
	strPage = request.getParameter(&quot;page&quot;);
	if (strPage == null) {
//表明在QueryString中没有page这一个参数，此时显示第一页数据
		intPage = 1;
	} else {//将字符串转换成整型
		intPage = Integer.parseInt(strPage);
		if (intPage &lt; 1)
			intPage = 1;
	}
	strSQL = &quot;select fkid,shjiaid from shop_shjiafk order by fkid desc&quot;;
	//执行SQL语句并获取结果集
	DBConn dd = new DBConn();
	sqlRst = dd.executeQuery(strSQL);
	//获取记录总数
	sqlRst.last();//光标在最后一行
	intRowCount = sqlRst.getRow();//获得当前行号
	//记算总页数
	intPageCount = (intRowCount + intPageSize - 1) / intPageSize;
	//调整待显示的页码
	if (intPage &gt; intPageCount)
		intPage = intPageCount;
%&gt;
&lt;html&gt;
	&lt;head&gt;
		&lt;script language=&quot;javascript&quot;&gt;
function newwin(url) {
var newwin=window.open(url,&quot;newwin&quot;,&quot;toolbar=no,location=no,directories=no,
status=no,menubar=no,scrollbars=yes,resizable=yes,width=600,height=450&quot;);
newwin.focus();
return false;
}
&lt;/script&gt;
		&lt;script language=&quot;javascript&quot;&gt;
function submit10()
{
self.location.replace(&quot;fenye.jsp&quot;)
}
&lt;/script&gt;
         &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=gbk&quot;&gt;
		&lt;title&gt;会员管理&lt;/title&gt;
	&lt;/head&gt;
	&lt;body&gt;
		&lt;form method=&quot;post&quot; action=&quot;fenye.jsp&quot;&gt;
			第
			&lt;%=intPage%&gt;
			页 共
			&lt;%=intPageCount%&gt;
			页
&nbsp;
			&lt;%
		if (intPage &lt; intPageCount) {
		%&gt;
			&lt;a href=&quot;fenye.jsp?page=&lt;%=intPage + 1%&gt;&quot;&gt;下一页 &lt;/a&gt;
			&lt;%
			}
			%&gt;
			&lt;%
			if (intPage &gt; 1) {
			%&gt;
			&lt;a href=&quot;fenye.jsp?page=&lt;%=intPage - 1%&gt;&quot;&gt; 上一页&lt;/a&gt;
			&lt;%
			}
			%&gt;
			转到第:
			&lt;input type=&quot;text&quot; name=&quot;page&quot; size=&quot;8&quot;&gt;
			页
			&lt;span&gt;&lt;input class=buttonface type=&quot;submit&quot; value=&quot;go&quot;
					name=&quot;cndok&quot;&gt; &lt;/span&gt;
		&lt;/form&gt;
		&lt;table border=&quot;1&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;&gt;
			&lt;tr&gt;
				&lt;th&gt;
					ID
				&lt;/th&gt;
				&lt;th&gt;
					用户名
				&lt;/th&gt;
				&lt;th width=&quot;8%&quot;&gt;
					删除
				&lt;/th&gt;
			&lt;/tr&gt;
			&lt;%
					if (intPageCount &gt; 0) {
					//将记录指针定位到待显示页的第一条记录上
					sqlRst.absolute((intPage - 1) * intPageSize + 1);
					//显示数据
					i = 0;
					String user_id, user_name;
					while (i &lt; intPageSize &amp;&amp; !sqlRst.isAfterLast()) {
						user_id = sqlRst.getString(1);
						user_name = sqlRst.getString(2);
			%&gt;
			&lt;tr&gt;
				&lt;td&gt;
					&lt;%=user_id%&gt;
				&lt;/td&gt;
				&lt;td&gt;
					&lt;%=user_name%&gt;
				&lt;/td&gt;
				&lt;td width=&quot;8%&quot; align=&quot;center&quot;&gt;
					&lt;a href=&quot;delete.jsp?user_id=&lt;%=user_id%&gt;&quot;
						onClick=&quot;return newwin(this.href);&quot;&gt;删除&lt;/a&gt;
				&lt;/td&gt;
			&lt;/tr&gt;
			&lt;%
						sqlRst.next();
						i++;
					}
				}
			%&gt;
		&lt;/table&gt;
	&lt;/body&gt;
&lt;/html&gt;
&lt;%
	dd.closeStmt();
	dd.closeConn();
%&gt;</pre></div></div>

<p>完成</p>
<img src="http://roamlog.info/?ak_action=api_record_view&id=29&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roamlog.info/archives/simpleness-pagination-of-jsp.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>笔记:tomcat5.5.23的连接池配置方法</title>
		<link>http://roamlog.info/archives/nots-of-configure-tomcat55-pool.html</link>
		<comments>http://roamlog.info/archives/nots-of-configure-tomcat55-pool.html#comments</comments>
		<pubDate>Wed, 28 Mar 2007 08:56:15 +0000</pubDate>
		<dc:creator>漫步</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[tomcat]]></category>

		<guid isPermaLink="false">http://roamlog.cn/index.php/2007/03/28/nots-of-configure-tomcat55-pool/</guid>
		<description><![CDATA[前些天我也写过一篇类似的文章,关于连接池配置的,今天我重新写过一篇,介绍不同的配置方法
环境搭建我就不多说了,我的环境是:

xp + jdk1.5 + tomcat5.5.23 + eclipse3.2.2 + myeclipse5.1.1GA + sqlserver2000

首先写个连接数据源的java类

SqlTestDS.java


package database;
import javax.sql.DataSource;
import javax.naming.*;
import java.sql.*;
public class SqlTestDS &#123;
private static DataSource ds = null;
static &#123;
init&#40;&#41;;
&#125;
private static void init&#40;&#41; &#123;
try &#123;
// 1、创建命名服务环境
Context ctx = new InitialContext&#40;&#41;;
if &#40;ctx == null&#41;
throw new Exception&#40;&#34;No Context&#34;&#41;;
&#160;
// 2、从JNDI中查询数据源对象
ds = &#40;DataSource&#41; ctx.lookup&#40;&#34;java:comp/env/jdbc/sqlserver&#34;&#41;;
&#160;
&#125; catch &#40;Exception e&#41; &#123;
e.printStackTrace&#40;&#41;;
&#125;
&#125;
&#160;
// 将构造函数定义为private权限是为了保证全局只有一个SqlTestDS实例
// 也就是实现了单例模式
private SqlTestDS&#40;&#41; &#123;
&#160;
&#125;
&#160;
public static Connection getConnection&#40;&#41; [...]]]></description>
			<content:encoded><![CDATA[<p>前些天我也写过一篇类似的文章,关于连接池配置的,今天我重新写过一篇,介绍不同的配置方法<br />
环境搭建我就不多说了,我的环境是:</p>
<blockquote><p>
xp + jdk1.5 + tomcat5.5.23 + eclipse3.2.2 + myeclipse5.1.1GA + sqlserver2000
</p></blockquote>
<p>首先写个连接数据源的java类</p>
<blockquote><p>
SqlTestDS.java
</p></blockquote>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">database</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.sql.DataSource</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.naming.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.sql.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SqlTestDS <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> DataSource ds <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">static</span> <span style="color: #009900;">&#123;</span>
init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// 1、创建命名服务环境</span>
<span style="color: #003399;">Context</span> ctx <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">InitialContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>ctx <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Exception</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;No Context&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// 2、从JNDI中查询数据源对象</span>
ds <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>DataSource<span style="color: #009900;">&#41;</span> ctx.<span style="color: #006633;">lookup</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;java:comp/env/jdbc/sqlserver&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// 将构造函数定义为private权限是为了保证全局只有一个SqlTestDS实例</span>
<span style="color: #666666; font-style: italic;">// 也就是实现了单例模式</span>
<span style="color: #000000; font-weight: bold;">private</span> SqlTestDS<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">Connection</span> getConnection<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">SQLException</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>ds <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">SQLException</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;数据源对象为空！&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// 3、从数据源中获取数据库连接</span>
<span style="color: #000000; font-weight: bold;">return</span> ds.<span style="color: #006633;">getConnection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><span id="more-28"></span><br />
再写个jsp文件,简单测试用.进行相关配置,接下来我将介绍和以前那篇不同的配置方法<br />
第一种<br />
在/META-INF目录下新建一个context.xml文件,写入以下内容</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">       docBase=&quot;myweb&quot;      //工程的虚拟目录
       path=&quot;/myweb&quot;          //访问路径
       reloadable=&quot;true&quot;&gt;
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resource</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;jdbc/mysql&quot;</span> <span style="color: #000066;">auth</span>=<span style="color: #ff0000;">&quot;Container&quot;</span> </span>
<span style="color: #009900;">              <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;javax.sql.DataSource&quot;</span></span>
<span style="color: #009900;">              <span style="color: #000066;">maxActive</span>=<span style="color: #ff0000;">&quot;100&quot;</span> <span style="color: #000066;">maxIdle</span>=<span style="color: #ff0000;">&quot;30&quot;</span> <span style="color: #000066;">maxWait</span>=<span style="color: #ff0000;">&quot;10000&quot;</span></span>
<span style="color: #009900;">              <span style="color: #000066;">driverClassName</span>=<span style="color: #ff0000;">&quot;com.microsoft.jdbc.sqlserver.SQLServerDriver&quot;</span></span>
<span style="color: #009900;">              <span style="color: #000066;">username</span>=<span style="color: #ff0000;">&quot;sa&quot;</span> <span style="color: #000066;">password</span>=<span style="color: #ff0000;">&quot;12345&quot;</span></span>
<span style="color: #009900;">              <span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=vnet&quot;</span></span>
<span style="color: #009900;">              <span style="color: #000066;">defaultAutoCommit</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">removeAbondoned</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #009900;">              <span style="color: #000066;">removeAbondonedTimeout</span>=<span style="color: #ff0000;">&quot;60&quot;</span> <span style="color: #000066;">logAbondoned</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>第二种<br />
在$CATALINA_HOME/conf/Catalina/localhost/  下新建一个和工程名同名的xml文件,如我的myweb.xml<br />
内容同上</p>
<p>当然还要配置一下web.xml</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resource-ref<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;res-ref-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>jdb/mysql<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/res-ref-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;res-type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>javax.sql.DataSource<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/res-type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;res-auth<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Container<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/res-auth<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/resource-ref<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>然后重启tomcat,测试<br />
访问路径为 http://localhost:8080/myweb/MyJsp.jsp<br />
配置成功</p>
<img src="http://roamlog.info/?ak_action=api_record_view&id=28&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roamlog.info/archives/nots-of-configure-tomcat55-pool.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>tomcat5.5.20的连接池配置方法</title>
		<link>http://roamlog.info/archives/the-method-of-configure-tomcat55-pool.html</link>
		<comments>http://roamlog.info/archives/the-method-of-configure-tomcat55-pool.html#comments</comments>
		<pubDate>Tue, 27 Feb 2007 11:35:04 +0000</pubDate>
		<dc:creator>漫步</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[tomcat]]></category>

		<guid isPermaLink="false">http://roamlog.cn/index.php/2007/02/27/the-method-of-configure-tomcat55-pool/</guid>
		<description><![CDATA[配置server.xml,在< /host > 标签前加入

&#60;context
       docBase=&#34;C:/eclipse/workspace/myweb/hello&#34;
        path=&#34;/hello&#34;
         reloadable=&#34;true&#34;
&#60;resource name=&#34;jdbc/mysql&#34; auth=&#34;Container&#34; type=&#34;javax.sql.DataSource&#34;
	maxActive=&#34;100&#34; maxIdle=&#34;30&#34; maxWait=&#34;10000&#34;
	driverClassName=&#34;com.mysql.jdbc.Driver&#34;
	username=&#34;root&#34; password=&#34;123456&#34;
	url=&#34;jdbc:mysql://localhost/testmysql&#34;
	defaultAutoCommit=&#34;true&#34; removeAbondoned=&#34;true&#34;
	removeAbondonedTimeout=&#34;60&#34; logAbondoned=&#34;true&#34;/&#62;
&#60;/context&#62;

配置web.xml

	&#60;resource-ref&#62;
		&#60;res-ref-name&#62;jdb/mysql&#60;/res-ref-name&#62;
		&#60;res-type&#62;javax.sql.DataSource&#60;/res-type&#62;
		&#60;res-auth&#62;Container&#60;/res-auth&#62;
	&#60;/resource-ref&#62;

]]></description>
			<content:encoded><![CDATA[<p>配置server.xml,在< /host > 标签前加入</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;context</span></span>
<span style="color: #009900;">       <span style="color: #000066;">docBase</span>=<span style="color: #ff0000;">&quot;C:/eclipse/workspace/myweb/hello&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;/hello&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">reloadable</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resource</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;jdbc/mysql&quot;</span> <span style="color: #000066;">auth</span>=<span style="color: #ff0000;">&quot;Container&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;javax.sql.DataSource&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">maxActive</span>=<span style="color: #ff0000;">&quot;100&quot;</span> <span style="color: #000066;">maxIdle</span>=<span style="color: #ff0000;">&quot;30&quot;</span> <span style="color: #000066;">maxWait</span>=<span style="color: #ff0000;">&quot;10000&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">driverClassName</span>=<span style="color: #ff0000;">&quot;com.mysql.jdbc.Driver&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">username</span>=<span style="color: #ff0000;">&quot;root&quot;</span> <span style="color: #000066;">password</span>=<span style="color: #ff0000;">&quot;123456&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;jdbc:mysql://localhost/testmysql&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">defaultAutoCommit</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">removeAbondoned</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">removeAbondonedTimeout</span>=<span style="color: #ff0000;">&quot;60&quot;</span> <span style="color: #000066;">logAbondoned</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/context<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>配置web.xml</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resource-ref<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;res-ref-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>jdb/mysql<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/res-ref-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;res-type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>javax.sql.DataSource<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/res-type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;res-auth<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Container<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/res-auth<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/resource-ref<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<img src="http://roamlog.info/?ak_action=api_record_view&id=26&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roamlog.info/archives/the-method-of-configure-tomcat55-pool.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

