开发者社区> 问答> 正文

DBCP object created 2013-04-28 00:03:53 ?报错

部署在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);");
%>

展开
收起
爱吃鱼的程序员 2020-06-22 19:36:39 557 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

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

    2020-06-22 19:36:54
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Apache Wicket User Guide - Ref 立即下载
In-Flux Limiting for a Multi-Tenant Logging Service 立即下载
Spark SQL:Past Present &Future 立即下载