在conf文件夹下中的server.xml中的
<host>和</host>中加入下面的代码:
<Context path="" docBase="ROOT" debug="0">
<Resource name="jdbc/sqlserver" auth="Container" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/sqlserver">
<parameter>
<name>factory</name>
<value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>oracle.jdbc.driver.OracleDriver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:microsoft:sqlserver://MICROSOF-BJER9M:1433;DatabaseName=basesql</value>
</parameter>
<parameter>
<name>username</name>
<value>sa</value>
</parameter>
<parameter>
<name>password</name>
<value>12345</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>20</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>10</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>-1</value>
</parameter>
</ResourceParams>
</Context>
然后conpool.jsp的代码如下:
<%@ page contentType="text/html; charset=gb2312" %>
<%@ page import="javax.naming.*"%>
<%@ page import="java.sql.*"%>
<%
Context initCtx = new InitialContext();
Context ctx=(Context) initCtx.lookup("java:comp/env");
Object obj=(Object) ctx.lookup("jdbc/sqlserver");
javax.sql.DataSource ds=(javax.sql.DataSource)obj;
Connection conn=ds.getConnection();
Statement stmt=conn.createStatement();
String strSql="select * from login";
ResultSet rs=stmt.executeQuery(strSql);
out.print("<table Border>");
out.print("<tr><td colspan=2 align=center>用户数据</td></tr>");
out.print("<tr>");
out.print("<td width=100>"+"用户姓名");
out.print("<td width=100>"+"用户密码");
out.print("</tr>");
while(rs.next())
{
out.print("<tr>");
out.print("<td>"+rs.getString(1)+"</td>");
out.print("<td>"+rs.getString(2)+"</td>");
out.print("</tr>");
}
out.print("</table>");
%>
出错如下:
javax.servlet.ServletException: Could not create resource factory instance, null
org.apache.jasper.runtime.PageContextImpl.doHandlePageException
(PageContextImpl.java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException
(PageContextImpl.java:758)
org.apache.jsp.conpool_jsp._jspService(conpool_jsp.java:89)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
问一下到底那里错了,
需要注明一下的是,我通过JDBC的方式成功连接,即用 con=DriverManager.getConnection("jdbc:microsoft:sqlserver://MICROSOF-BJER9M:1433;DatabaseName=basesql","sa","12345");
已经连接成功
但是在配置地址池的时候就出现了上面的错误,请问到底那里错了
[此贴子已经被作者于2006-8-4 15:35:07编辑过]