jsp+sqlserver2000+连接池 配置问题 懂的请进
jsp+sqlserver2000+连接池 环境搭建
平台:
1.tomcat 6.0
2.server 2003
3.iis 6.0
4.java 1.6.0_02
5.sql server 2000
配置步骤:
1.在tomcat安装目录下c:tomcat\lib放入下好的三个微软驱动程序:msbase.jar,mssqlserver.jar,msutil.jar
2.建数据库test,建表test(name,id)
3.配置server.xml,放在下列代码 <host> </host> 之间
<Context path= "/test " docBase= "test " debug= "5 " reloadable= "true " crossContext= "true ">
<Resource name= "jdbc/TestDB " auth= "Container " type= "javax.sql.DataSource "/>
<ResourceParams name= "jdbc/TestDB ">
<parameter>
<name> factory </name>
<value> org.apache.commons.dbcp.BasicDataSourceFactory </value>
</parameter>
<!-- Maximum number of dB connections in pool. Make sure you
configure your MYSQLd max_connections large enough to handle
all of your db connections. Set to 0 for no limit.
-->
<parameter>
<name> maxActive </name>
<value> 100 </value>
</parameter>
<!-- Maximum number of idle dB connections to retain in pool.
Set to 0 for no limit.
-->
<parameter>
<name> maxIdle </name>
<value> 30 </value>
</parameter>
<!-- Maximum time to wait for a dB connection to become available
in ms, in this example 10 seconds. An Exception is thrown if
this timeout is exceeded. Set to -1 to wait indefinitely.
-->
<parameter>
<name> maxWait </name>
<value> 10000 </value>
</parameter>
<!-- MSSQLserver dB username and password for dB connections -->
<parameter>
<name> username </name>
<value> sa </value>
</parameter>
<parameter>
<name> password </name>
<value> sa </value>
</parameter>
<!-- Class name for mssqlserver JDBC driver -->
<parameter>
<name> driverClassName </name>
<value> com.microsoft.jdbc.sqlserver.SQLServerDriver </value>
</parameter>
<!-- The JDBC connection url for connecting to your mssqlserver dB.-->
<parameter>
<name> url </name>
<value> jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=test </value>
</parameter>
</ResourceParams>
</Context>
4.在web.xml的中 <web-app> </web-app> 放入下列代码
<resource-ref>
<description> connectDB test </description>
<res-ref-name> jdbc/TestDB </res-ref-name>
<res-type> javax.sql.DataSource </res-type>
<res-auth> Container </res-auth>
</resource-ref>
5.在c:tomcat\webapps新建一个test.jsp
<%@ page contentType= "text/html;charset=GBK "%>
<%@ page import= "javax.naming.* "%>
<%@ page import= "javax.sql.* "%>
<%@ page import= "java.sql.* "%>
<%
try
{
Context ctx=new InitialContext();
if(ctx==null)
throw new Exception( "没有匹配的环境 ");
DataSource ds=(DataSource)ctx.lookup( "java:comp/env/jdbc/TestDB ");
if(ds==null)
throw new Exception( "没有匹配数据库 ");
Connection cnn=ds.getConnection();
Statement stmt=cnn.createStatement();
ResultSet rs=stmt.executeQuery( "select * from test ");
}
finally
{
out.print( "error msg! ");
}
%>
6.重启tomcat
/--------------------------------------------
测试:http://localhost:8080/test/test.jsp
--------------报错----------------------
org.apache.jasper.JasperException: An exception occurred processing JSP page /test.jsp at line 18
15: if(ds==null)
16: throw new Exception( "没有匹配数据库 ");
17:
18: Connection cnn=ds.getConnection();
19: Statement stmt=cnn.createStatement();
20: ResultSet rs=stmt.executeQuery( "select * from test ");
21: }
-------------------------------------------
我想我应该说得比较清楚了吧,希望各位帮我看下,这个问题困扰我10多天了,希望高手指点下
[解决办法]
你把
Connection cnn=ds.getConnection();
Statement stmt=cnn.createStatement();
ResultSet rs=stmt.executeQuery( "select * from test ");
单独做异常处理...加上try/catch试试看....
[解决办法]
5.在c:tomcat\webapps新建一个test.jsp
================================
你这个test.jsp页面直接就放在了webapps下面,不是在某个项目下面吗?
[解决办法]
异常没贴出来看看
我的异常网推荐解决方案:An exception occurred processing JSP page,http://www.myexception.cn/j2se/33144.html