tomcat 5.5 连接池配置
Tomcat5.5 连接池配置总共三种方案进行:
1、配置tomcat下的工程文件:
在Tomcat安装目录中的\conf\Catalina\localhost下的工程名.xml中的拷入如下内容:
<Resource name="jdbc/oracle" auth="Container"
type="javax.sql.DataSource" username="test" password="password"
driverClassName="oracle.jdbc.driver.OracleDriver" url="jdbc:oracle:thin:@10.60.108.250:1521:lgsl"
maxActive="8" maxIdle="4"/>
在项目中servlet程序中进行测试:
doGet方法中写入如下方法:
try
{
System.out.println("test jndi");
InitialContext ic = new InitialContext();
DataSource ds = (DataSource) ic.lookup("java:comp/env/jdbc/oracle");
System.out.println(ds.getClass());
Connection conn = ds.getConnection();
if(conn != null)
{
System.out.println(conn.getClass());
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("select batchDate,batchIndex from AlipayOpenAccountBatch");
while(rs.next())
{
System.out.print(rs.getString("batchDate") + ",");
System.out.println(rs.getInt("batchIndex") + ";");
}
}
System.out.println("test jndi end");
}
catch(Exception e)
{
e.printStackTrace();
}
在浏览器中输入配置的好的地址:后台打印出理想结果。
2、配置tomcat下的context.xml文件:
在Tomcat安装目录中的\conf下的context.xml中的拷入如下内容:
<Resource name="jdbc/oracle" auth="Container"
type="javax.sql.DataSource" username="test" password="password"
driverClassName="oracle.jdbc.driver.OracleDriver" url="jdbc:oracle:thin:@10.60.108.250:1521:lgsl"
maxActive="8" maxIdle="4"/>
在项目中servlet程序中进行测试:
doGet方法中写入如下方法:
try
{
System.out.println("test jndi");
InitialContext ic = new InitialContext();
DataSource ds = (DataSource) ic.lookup("java:comp/env/jdbc/oracle");
System.out.println(ds.getClass());
Connection conn = ds.getConnection();
if(conn != null)
{
System.out.println(conn.getClass());
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("select batchDate,batchIndex from AlipayOpenAccountBatch");
while(rs.next())
{
System.out.print(rs.getString("batchDate") + ",");
System.out.println(rs.getInt("batchIndex") + ";");
}
}
System.out.println("test jndi end");
}
catch(Exception e)
{
e.printStackTrace();
}
在浏览器中输入配置的好的地址:后台打印出理想结果。
3、配置tomcat下的service.xml和工程.xml和项目的web.xml文件:
在Tomcat安装目录中的\conf下的service.xml中<GlobalNamingResources/>节点下的拷入如下内容:
<Resource name="jdbc/oracle" auth="Container"
type="javax.sql.DataSource" username="test" password="password"
driverClassName="oracle.jdbc.driver.OracleDriver" url="jdbc:oracle:thin:@10.60.108.250:1521:lgsl"
maxActive="8" maxIdle="4"/>
在Tomcat安装目录中的\conf\Catalina\localhost下的工程名.xml中的拷入如下内容:
<Resource name="jdbc/oracle" auth="Container"
type="javax.sql.DataSource" username="test" password="password"
driverClassName="oracle.jdbc.driver.OracleDriver" url="jdbc:oracle:thin:@10.60.108.250:1521:lgsl"
maxActive="8" maxIdle="4"/>
在项目的web.xml文件中拷入如下内容:
<resource-ref>
<res-ref-name>jdbc/oracle</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
在项目中servlet程序中进行测试:
doGet方法中写入如下方法:
try
{
System.out.println("test jndi");
InitialContext ic = new InitialContext();
DataSource ds = (DataSource) ic.lookup("java:comp/env/jdbc/oracle");
System.out.println(ds.getClass());
Connection conn = ds.getConnection();
if(conn != null)
{
System.out.println(conn.getClass());
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("select batchDate,batchIndex from AlipayOpenAccountBatch");
while(rs.next())
{
System.out.print(rs.getString("batchDate") + ",");
System.out.println(rs.getInt("batchIndex") + ";");
}
}
System.out.println("test jndi end");
}
catch(Exception e)
{
e.printStackTrace();
}
在浏览器中输入配置的好的地址: 后台打印出理想结果。
疑惑和自己的认为:
采用方案1:只能在本工程使用,测试其他工程不可使用,配置根据项目配置,灵活。
采用方案2:tomcat下的工程都可使用,测试通过,比较灵活。
方案3比较麻烦由于时间原因(在工作地偷偷进行的,管的有点变态,不可进行其他事项),这个未进行比对,加之配置有些稍微复杂。
为何方案1,2,配置这么简单可行,没时间在其他地方测试,也没时间看tomcat源码,待解决。
页:
[1]