JAVA的连接池配置失败
The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Exception in JSP: /ljc.jsp:20
17: }catch(Exception e){
18:
System.err.println( "链接池配置失败! ");
19: }
20: conn.close();
21: %>
22: </body>
23: </html>
我的连接池的配置和代码是:
1. 先备份Tomcat/conf下的所有的文件。
2. 在Tomcat /conf/server.xml中 </GlobalNamingResources> 之前加入:
<Resource name= "jdbc/system_users1 " type= "javax.sql.DataSource " driverClassName= "com.microsoft.jdbc.sqlserver.SQLServerDriver " maxIdle= "10 " maxWait= "10000 " username= "sa " password= " " url= "jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=system_users1 " maxActive= "300 "/>
3. 在conf下面的context.xml文件中, </Context> 之前加入:
<ResourceLink name= "jdbc/system_users1 " global= "jdbc/system_users1 " type= "javax.sql.DataSourcer "/>
4. 在你的web应用下面的WEB-INF中找到web.xml,在最后 </web-app> 之前加入:
<resource-ref>
<description> system_users1 Connection </description>
<res-ref-name> jdbc/ system_users1 </res-ref-name>
<res-type> javax.sql.DataSource </res-type>
<res-auth> Container </res-auth>
</resource-ref>
5. 编写JavaBean、JSP或Servlet测试连接池。例如,使用JSP测试的源代码如下:
<%@ page contentType= "text/html; charset=gb2312 " language= "java " import= "java.sql.*,javax.sql.*,javax.naming.* "
errorPage= " " %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 " />
<title> Untitled Document </title>
</head>
<body>
<%
DataSource ds = null;
Connection conn = null;
try{
Context ctx=new InitialContext();
ds=(DataSource)ctx.lookup( "java:comp/env/jdbc/ system_users1 ");
conn = ds.getConnection();
out.println(conn);
}catch(Exception e){
System.err.println( "链接池配置失败! ");
}
conn.close();
%>
</body>
</html>
6. 测试成功后,将从Tomcat连接池得到连接的代码封装成一个连接池Bean,以后直接从这个类的相关方法得到连接,使用完后,直接调用.close()方法将连接返还给连接池。连接池Bean的代码怎么写?
------解决方案--------------------ds=(DataSource)ctx.lookup( "java:comp/env/jdbc/ system_users1 ");是不是jdbc后面多了一个空格啊
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html