我的连接池为什么取不到连接?
在server.xml中 </host> 上面加入:
<Context
docBase= "D:\eclipse3.2\workspace\test\WebRoot "
path= "/test "
reloadable= "true " >
<Resource name= "jdbc/rat " auth= "Container " type= "javax.sql.DataSource "
maxActive= "100 " maxIdle= "30 " maxWait= "10000 "
driverClassName= "com.microsoft.jdbc.sqlserver.SQLServerDriver "
username= "sa " password= " "
url= "jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=test "
defaultAutoCommit= "true " removeAbondoned= "true "
removeAbondonedTimeout= "60 " logAbondoned= "true "/>
</Context>
在web.xml文件中加入:
<resource-ref>
<description> Sql Server Datasource </description>
<res-ref-name> jdbc/rat </res-ref-name>
<res-type> javax.sql.DataSource </res-type>
<res-auth> Container </res-auth>
</resource-ref>
项目文件夹是test
数据库:test
测试页:test.jsp
<%@ page contentType= "text/html;charset=gb2312 " %>
<%@ page import= "javax.naming.* " %>
<%@ page import= "javax.naming.Context " %>
<%@ page import= "javax.sql.DataSource " %>
<%@ page import= "javax.naming.InitialContext " %>
<%@ page import= "java.sql.* " %>
<%
DataSource ds=null;
try
{
Context initCtx=new InitialContext();
Context envCtx=(Context)initCtx.lookup( "java:comp/env ");
file://从Context中lookup数据源
ds=(DataSource)envCtx.lookup( "jdbc/rat ");
if(ds!=null)
{
out.println( "DataSource!OK! ");
out.println( " <br> ");
Connection conn=ds.getConnection();
Statement stmt=conn.createStatement();
ResultSet rst=stmt.executeQuery( "select * from test ");
out.println( "DATA out! ");
while(rst.next())
{
out.println( "bookName: "+rst.getString( "test "));
out.println( " <br> ");
}
}
else
out.println( "失败! ");
}
catch(Exception ne)
{
out.println(ne);
}
%>
tomcat5.5.20解压版
JDK5
请问问题出在哪?
------解决方案---