org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
[此贴子已经被作者于2006-12-30 16:45:58编辑过]
/////////////////////////////JSP文件//////////////////////////
<%@ page import="javax.naming.Context" %>
<%@ page import="javax.sql.DataSource"%>
<%@ page import="javax.naming.InitialContext"%>
<%@ page import="java.sql.*"%>
<%
DataSource ds = null;
try{
Connection conn = com.jspdev.util.DatabaseConn.getConnection();
if(conn!=null)
{
out.println("Connection is OK!");
out.println("<br>");
Statement stmt=conn.createStatement();
ResultSet rst=stmt.executeQuery("select * from user_info");
while(rst.next())
{
out.println(rst.getString("userId"));
out.println("<br>");
}
}
else
out.println("Fail!");
}
catch(Exception ne){ out.println(ne);}
%>
//////////////////////////////java文件//////////////////////////
import java.sql.*;
import javax.naming.*;
import javax.sql.DataSource;
public class DatabaseConn {
public static synchronized Connection getConnection() throws Exception
{
try
{
Context initCtx = new javax.naming.InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource)envCtx.lookup("jdbc/jspdev"); ;
return ds.getConnection();
}
catch(SQLException e)
{
throw e;
}
catch(NamingException e)
{
throw e;
}
}
}
/////////////////server.xml////////////////////
............
<Context path="/jspdev" docBase="jspdev" debug="0" reloadable="true"
crossContext="true">
<Resource name="jdbc/jspdev" auth="Container" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/jspdev">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:microsoft:sqlserver://192.168.1.3:1433;DatabaseName=jspdev</value>
</parameter>
<parameter>
<name>username</name>
<value>sa</value>
</parameter>
<parameter>
<name>password</name>
<value>123</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>
..........
[此贴子已经被作者于2006-12-30 14:14:34编辑过]
/conf/Catalina/localhost下jspdev.xml配置了么?
名称得一致
jspdev.xml没有啊,请问应该怎么配置啊??
希望能详细一点呢
要设置 conf\server.xml 这个我设置好了
conf\context.xml 这个也是
conf\web.xml 这个不知道在那里加,有的论坛说不用设置的,我加了楼上的代码还是一样的出错
conf\Catalina\localhost\jspdev.xml 不知道怎么设置啊
[此贴子已经被作者于2006-12-31 17:26:33编辑过]