1.通过http://localhost:8080/admin建立了一个名为aaa的JNDI的连接池;
2.在项目的web.xml上增加:
<resource-ref>
<res-ref-name>aaa</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
3.写了一个测试的JSP;
<%@ page import="java.sql.*"%>
<%@ page import="javax.sql.*"%>
<%@ page import="javax.naming.*"%>
<%
DataSource ds = null;
try{
InitialContext ctx=new InitialContext();
ds=(DataSource)ctx.lookup("java:comp/env/aaa");
System.out.println(ds);
Connection conn = ds.getConnection();
System.out.println(conn);
Statement stmt = conn.createStatement();
String strSql = " select * from tbTest";
ResultSet rs = stmt.executeQuery(strSql);
while(rs.next())
{
System.out.println(rs.getString(1));
}
}
catch(Exception ex){
ex.printStackTrace();
}
%>
出现异常:
org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
换了一个Tomcat的版本 5.0.28,
还是会出现这个问题!
------解决方法--------------------------------------------------------
是不是没有驱动程序啊?
------解决方法--------------------------------------------------------
Here's what I did:
1. added resource-ref entry to web.xml
<resource-ref>
<description>DataSource for HR app</description>
<res-ref-name>jdbc/hrDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
2. deployed WAR file to Tomcat
3. inside <tomcat_install_dir>\conf\Catalina\localhost\<my_app_context>.xml, I made sure that I had the
resource
entry in the file, which should have been populated upon deployment of the WAR file to Tomcat:
<Resource auth="Container" description="DataSource for HR app" name="jdbc/hrDS" type="javax.sql.DataSource" />