首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

100分请求分析异常原因

2013-09-11 
100分请求分析错误原因为什么我按着F5不停的刷新就会出现这样的错误,我的数据库连接好像用完后就关闭了呀G

100分请求分析错误原因

为什么我按着F5不停的刷新就会出现这样的错误,我的数据库连接好像用完后就关闭了呀

GGJJDDMM帮我分析分析


错误如下

HTTP Status 500 - 

--------------------------------------------

type Exception report

message 

description The server encountered an internal error () that prevented it from fulfilling this request.

exception 

org.apache.jasper.JasperException: An exception occurred processing JSP page /web/mall/sort.jsp at line 9

6: <head>
7: <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
8: <jsp:useBean id="product" scope="page" class="cn.com.web.mall.bean.Product"></jsp:useBean>
9: <jsp:useBean id="data" scope="page" class="cn.com.util.DataBase"></jsp:useBean>
10: <title>Insert title here</title>
11: <link href="style/home.css" rel="stylesheet" type="text/css" />
12: </head>


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:515)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:408)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


root cause 

javax.servlet.ServletException: org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot get a connection, pool exhausted
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:855)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:784)
org.apache.jsp.web.mall.sort_jsp._jspService(sort_jsp.java:365)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:384)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


root cause 

org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot get a connection, pool exhausted
org.apache.tomcat.dbcp.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:103)
org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540)
cn.com.util.DataBase.<init>(DataBase.java:22)
org.apache.jsp.web.mall.sort_jsp._jspService(sort_jsp.java:81)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:384)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


root cause 

java.util.NoSuchElementException: Timeout waiting for idle object
org.apache.tomcat.dbcp.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:756)
org.apache.tomcat.dbcp.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:95)
org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540)
cn.com.util.DataBase.<init>(DataBase.java:22)
org.apache.jsp.web.mall.sort_jsp._jspService(sort_jsp.java:81)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:384)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)


org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


note The full stack trace of the root cause is available in the Apache Tomcat/6.0.10 logs.


--------------------------------------------

Apache Tomcat/6.0.10

[解决办法]
root cause

org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot get a connection, pool exhausted 

连接池中可用数据库连接耗尽,你可能没关闭连接。

[解决办法]
root cause

org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot get a connection, pool exhausted

连接池中可用数据库连接耗尽,你可能没关闭连接
顶!
每次刷新都建立一个连接了?连接耗尽后没有判断继续连接了吧?
[解决办法]
肯定有没有关闭的连接
[解决办法]
说说你是如何申明connection变量,如何关闭的吧,
肯定是有问题了
[解决办法]

这是数据库类,所有的数据库操作都是基于此类的,代码如下


package cn.com.util;
import java.sql.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
public class DataBase 
{
public DataSource ds;
public Connection conn=null;
public DataBase()throws Exception
{
Context ctx = new InitialContext();

if(ctx==null)
{
throw new Exception("No Context");
}
else
{
 
ds = (DataSource)ctx.lookup("java:comp/env/jdbc/gelou");
conn=ds.getConnection();
}
}
/*打开并返回一个数据库连接*/
public Connection getConnection()throws Exception 
{

return conn;
}
/*关闭打开的连接*/
public void closeConnection(Connection con)
{

try
{
if(con!=null)
{
con.close();

con=null;

}

}
catch(Exception ex)
{

ex.printStackTrace();
}
}

public void closePreparedStatement(PreparedStatement pstmt)
{
try{
if(pstmt!=null)
{
pstmt.close();
}
}
catch(Exception e)
{
e.printStackTrace();
}
}

public void closeResultSet(ResultSet rs){
try{
if(rs!=null)
{
rs.close();
rs=null;
}
}
catch(Exception e)
{
e.printStackTrace();
}
}

/*返回ResultSet*/
public ResultSet executeQuery(String m_SQL) 
{
ResultSet rs=null;
try 
{
Connection con =getConnection();
PreparedStatement pstmt =con.prepareStatement(m_SQL);
rs = pstmt.executeQuery();
}
catch (Exception ex)
{
System.err.println("sql_data.executeQuery:" + ex.getMessage());
}
return rs;
}
/*插入数据*/
public boolean executeInsert(String m_SQL)throws Exception
{
Connection con =getConnection();
PreparedStatement pstmt =con.prepareStatement(m_SQL);
try
{
pstmt.executeUpdate();

closePreparedStatement(pstmt);
closeConnection(con);
return true;
}
catch (Exception ex)
{
System.err.println(ex.getMessage());
closePreparedStatement(pstmt);
closeConnection(con);
return false;
}
}
//更新数据库数据
public boolean executeUpdate(String m_SQL)throws Exception


{
Connection con =getConnection();
PreparedStatement pstmt =con.prepareStatement(m_SQL);
try {
pstmt.executeUpdate();
closePreparedStatement(pstmt);
closeConnection(con);
return true;

} catch (Exception ex) 
{
System.err.println("aq.executeQuery: " + ex.getMessage());
closePreparedStatement(pstmt);
closeConnection(con);
return false;
}
}
}

[解决办法]
可以去这里找找资料。
[解决办法]
executeQuery 好像里面没关闭链接
要是连接池的话 closePreparedStatement 应该没啥用,就conn.close()就行了


[解决办法]

如果返回ResultSet 就不能关闭连接
[解决办法]

我很想知道我这样写是否正确
[解决办法]
你返回RS 却又没关闭connection

导致数据库连接耗尽

最好不要返回RS,而是返回经过处理封装好的对象

然后在原来的代码里加上关闭connection的代码

finally{
......
conn.close();
set conn=null;
......
}
[解决办法]
修改executeQuery方法 每次取完后关闭conn
[解决办法]
谢啦 

我的异常网推荐解决方案:An exception occurred processing JSP page,http://www.myexception.cn/j2se/33144.html
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html

热点排行