MS SQL2000连接池错误,谢谢
在连接MS SQL2000时出现了错误
org.apache.tomcat.dbcp.dbcp.
SQLNestedException: Cannot load JDBC driver class 'com.microsoft.jdbc.sqlserver.SQLServerDriver '
server.xml中相关代码是
<Resource
name= "jdbc/FWeb "
type= "javax.sql.DataSource "
driverClassName= "com.microsoft.jdbc.sqlserver.SQLServerDriver "
password= "111111 "
maxIdle= "2 "
maxWait= "5000 "
username= "sa "
url= "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=Web "
maxActive= "4 "/>
然后我在conf\Catalina\localhost下,也建了个用工程名命名的XML文件,把上面那些代码加进去了的
在web.xml中我也加入了
<resource-ref>
<description> SqlServer Datasource example </description>
<res-ref-name> jdbc/FWeb </res-ref-name>
<res-type> javax.sql.DataSource </res-type>
<res-auth> Container </res-auth>
</resource-ref>
测试代码是
<%@ 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 initContext = new InitialContext();
Context envContext = (Context)initContext.lookup( "java:comp/env ");
DataSource ds = (DataSource)envContext.lookup( "jdbc/FWeb ");
Connection conn = ds.getConnection();
Statement stmt = conn.createStatement();
ResultSet rst=stmt.executeQuery( "select count(*) from commonuser ");
out.println( "以下是从数据库中读取出来的数据 ");
while(rst.next())
{
rst.getString(1);
}
}
catch(Exception ne)
{
out.println(ne);