DBCP object created 2013-04-28 00:03:53 by the following code was never closed

发布于 2021-11-14 18:15:37 字数 6321 浏览 986 评论 1

部署在tomcat下的一个工程,工程里面的default.js调用了一个sc.jsp,后台日志时不时的就会报错,有哪位大神能不能帮偶看看问题出在哪哇

org.apache.tomcat.dbcp.dbcp.AbandonedTrace$AbandonedObjectException: DBCP object created 2013-04-28 00:03:53 by the following code was never closed:
详细的报错代码如下:
org.apache.tomcat.dbcp.dbcp.AbandonedTrace$AbandonedObjectException: DBCP object created 2013-04-28 00:03:53 by the following code was never closed:
	at org.apache.tomcat.dbcp.dbcp.AbandonedTrace.setStackTrace(AbandonedTrace.java:139)
	at org.apache.tomcat.dbcp.dbcp.AbandonedObjectPool.borrowObject(AbandonedObjectPool.java:81)
	at org.apache.tomcat.dbcp.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:106)
	at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
	at org.apache.jsp.sc_jsp.getConnection(sc_jsp.java:35)
	at org.apache.jsp.sc_jsp.countbytitle(sc_jsp.java:45)
	at org.apache.jsp.sc_jsp._jspService(sc_jsp.java:173)
	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
	at org.apache.tomcat.util.net.AprEndpoint$SocketWithOptionsProcessor.run(AprEndpoint.java:1771)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
	at java.lang.Thread.run(Thread.java:662)

function countbytitle(titleurl){
var url = "http://localhost:8080/helpsearch/sc.jsp?q=" + cjkEncode(titleurl);
var js_obj = document.createElement("script");
js_obj.type = "text/javascript";
js_obj.setAttribute("src",url);
document.body.appendChild(js_obj);
};

sc.jsp代码如下:

<%@ page language="java" contentType="application/x-javascript; charset=utf-8"%>
<%@ page import="java.io.File" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.Statement" %>


<%@ page import="javax.naming.Context" %>
<%@ page import="javax.naming.InitialContext" %>
<%@ page import="javax.sql.DataSource" %>

<%!
 public static Connection getConnection() { 
    	Connection conn = null;
        try {  
        	Context context = new InitialContext();
			DataSource datasource = (DataSource) context.lookup("java:comp/env/jdbc/mysql");
			conn = datasource.getConnection(); 
        } catch (Exception e) {  
            e.printStackTrace();   
        }  
        return conn;  
    } 
private static String countbytitle(String titleurl) throws Exception{
	    StringBuffer data = new StringBuffer("[");
			//int yesnum = 25;
			//int nonum = 30;
		Connection conn = getConnection();
		Statement st = conn.createStatement();
		ResultSet rs = null;
		String sqlyes = "";
		String sqlno = "";
		int yesnum = 0;
		int nonum = 0;
		sqlyes = "SELECT count(*) FROM doc_solveproblem WHERE doctitle = '"+titleurl+"' AND 703solveproblem = 'yes'";
			rs = st.executeQuery(sqlyes);
			if (rs.next()) {
				yesnum = rs.getInt(1);
			}
		sqlno = "SELECT count(*) FROM doc_solveproblem WHERE doctitle = '"+titleurl+"' AND 703solveproblem = 'no'";
			rs = st.executeQuery(sqlno);
			if (rs.next()) {
				nonum = rs.getInt(1);
			}
			data.append(""");
				data.append(yesnum + "",");
				data.append(""");
				data.append(nonum + """);
			st.close();
		conn.close();
		data.append("]");
			System.out.println(yesnum);
			System.out.println(nonum);
			return data.toString();
	    }

private static String cjkDecode(String text) throws Exception {
		if (text == null) {
			return "";
		}

		//查找没有 "[", 直接返回.
		if (text.indexOf('[') == -1) {
			return text;
		}

		StringBuffer newTextBuf = new StringBuffer();
		for (int i = 0; i < text.length(); i++) {
			char ch = text.charAt(i);
			if (ch == '[') {
				int rightIdx = text.indexOf(']', i + 1);
				if (rightIdx > i + 1) {
					String subText = text.substring(i + 1, rightIdx);
					//james:主要是考虑[CDATA[]]这样的值的出现
					if (subText.length() > 0) {
						ch = (char) Integer.parseInt(subText, 16);
					}

					i = rightIdx;
				}
			}

			newTextBuf.append(ch);
		}

		return newTextBuf.toString();
	}

%>

<%
		String titleurl = cjkDecode(request.getParameter("q"));
    	String data = "[]";
		try {
			data = countbytitle(titleurl);
		} catch (Exception e) {
			e.printStackTrace();
		}
		response.getWriter().print("var data = " + data + ";");
		response.getWriter().print("var titleurl = '" + titleurl + "';");
		response.getWriter().print("test(titleurl, data);");
%>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱的故事 2021-11-18 05:22:23

看下你的数据库连接有没有关闭...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文