日期:2014-05-18  浏览次数:20688 次

数据池配置问题
请高手指导!!!
怎么配置数据库连接池(tomcat5.0+sql   server2000)

------解决方案--------------------
100094
------解决方案--------------------
%tomcat_home%\conf\server.xml鏂囦欢涓紝鍦ㄤ綘鐨刢ontext涓姞鍏ュ涓嬩唬鐮佸嵆鍙細
<Context path= "/.....................>
<Resource auth= "Container " description= "SQL Server Connection " name= "jdbc/dataSources " type= "javax.sql.DataSource "/>
<ResourceParams name= "jdbc/dataSources ">
<parameter>
<name> factory </name>
<value> org.apache.commons.dbcp.BasicDataSourceFactory </value>
</parameter>
<parameter>
<name> maxActive </name>
<value> 50 </value>
</parameter>
<parameter>
<name> maxWait </name>
<value> 1000 </value>
</parameter>
<parameter>
<name> username </name>
<value> sa </value>
</parameter>
<parameter>
<name> password </name>
<value> sa </value>
</parameter>
<parameter>
<name> url </name> <value> jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=netstore </value>
</parameter>
<parameter>
<name> driverClassName </name>
<value> com.microsoft.jdbc.sqlserver.SQLServerDriver </value>
</parameter>
<parameter>
<name> maxIdle </name>
<value> 30 </value>
</parameter>
</ResourceParams>
</Context>
------解决方案--------------------
: <%@ page contentType= "text/html; charset=gb2312 " %>
<%@ page import= "javax.naming.Context " %>
<%@ page import= "javax.sql.DataSource "%>
<%@ page import= "javax.naming.InitialContext "%>
<%@ page import= "java.sql.* "%>
<%

try{
Context initCtx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup( "java:comp/env/jdbc/sqlserver ");
out.println( "已经获得DataSource! ");
out.println( " <br/> ");
Connection conn = ds.getConnection();
Statement stmt=conn.createStatement();
ResultSet rst=stmt.executeQuery( "select * from guest ");
out.println( "以下是从数据库中读取出来的数据 ");
while(rst.next())
{
out.println( "num: "+rst.getString(1));
out.println( " <br/> ");
}
}

catch(Exception ne)
{
out.println(ne);
}
%>

------解决方案--------------------
关注
------解决方案--------------------
java命名空间问题, 在SEVER.XML <GlobalNamingResources> 下加入这段话 就可以了

<ResourceLink name= "jdbc/connectdb " type= "javax.sql.DataSource " global= "jdbc/dataSources "/>