当前位置: 代码迷 >> Eclipse >> 测试数据库连接池有关问题
  详细解决方案

测试数据库连接池有关问题

热度:121   发布时间:2016-04-23 14:18:55.0
测试数据库连接池问题
我在做一个测试数据库连接池的试验时,在eclipse之外测试,即通过系统托盘启动Tomcat,再把testdb.jsp复制到ROOT目录下,在浏览器中打开网址访问,一切正常,能显示查询内容。但是在eclipse之内测试,即在eclipse中启动Tomcat,在浏览器中输入http://localhost:8080/myweb/testdb.jsp,页面却无内容。同样,在eclipse中直接运行项目,页面也没有显示内容,
请问这是怎么回事???

页面代码如下:
<%@ page language="java" contentType="text/html; charset=GBK"
  pageEncoding="GBK"%>
<%@ page import="java.sql.*"%>
<%@ page import="javax.sql.*"%>
<%@ page import="javax.naming.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
Connection con=null;
Statement sm=null;
ResultSet rs=null;
try{
InitialContext ctx=new InitialContext();
DataSource ds=(DataSource)ctx.lookup("java:comp/env/jdbc/mysql");
con = ds.getConnection();
sm = con.createStatement();
rs = sm.executeQuery("select * from iuser");
while(rs.next())
out.println(rs.getString("name")+",");
}catch(Exception e){
e.printStackTrace();
}finally{
if(rs != null){
try{rs.close();}catch(SQLException e){e.printStackTrace();}
rs = null;
}
if(sm != null){
try{sm.close();}catch(SQLException e){e.printStackTrace();}
sm = null;
}
if(con != null){
try{con.close();}catch(SQLException e){e.printStackTrace();}
con = null;
}
}
%>

在eclipes中运行时控制台信息如下:

java.security.AccessControlException: access denied (java.lang.RuntimePermission accessClassInPackage.org.apache.tomcat.dbcp.pool.impl)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)
at java.security.AccessController.checkPermission(AccessController.java:546)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at java.lang.SecurityManager.checkPackageAccess(SecurityManager.java:1512)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:273)
at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1165)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
at org.apache.jsp.index_jsp._jspService(index_jsp.java:57)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:244)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:276)
at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:162)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:262)
at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:52)
at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:171)
  相关解决方案