连接泄露的问题
我用的是MyEclipse6.5、oc4j、jdk1.4但是我运行界面时,会报这样的异常,它不影响界面操作,但是时间长了会影响操作速度,使界面加载很慢。
以下是报的异常:
OrionCMTConnection not closed, check your code!
Logical connection not closed, check your code!
(Use -Djdbc.connection.debug=true to find out where the leaked connection was created)
我的action 代码:
public class MerchantQueryAction extends TPBaseAction {
public ActionForward executeAction(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws TPActionException {
String forwardPage = null;
Connection conn = null;
try {
conn = DBUtil.getConnection();
forwardPage = execManager(conn, form, request);// 执行业务操作
return mapping.findForward(forwardPage);
} catch (Exception e) {
e.printStackTrace();
throw new TPActionException(e);
} finally {
forwardPage = null;
DBUtil.close(conn);
}
}
private String execManager(Connection conn, ActionForm form,HttpServletRequest request) throws Exception {
DynaValidatorForm dyForm = (DynaValidatorForm) form;
RowSetPage rsp = null;
MerchantModel merModel = null ;
int pageNum = 1;
// 取得页面的欲翻页页码
if (request.getParameter("pageNum") != null && !request.getParameter("pageNum").equals("")) {
pageNum = Integer.parseInt(request.getParameter("pageNum"));
}
merModel=formToModel(dyForm);
//调用manager终端信息共享池查询方法
rsp=MerchantDAOExt.queryMerchant(merModel, pageNum, IConstants.PAGE_SIZE, conn);
request.setAttribute("RowSetPage", rsp);
request.setAttribute("mchntId", dyForm.get("mchntId"));
request.setAttribute("mchntName", dyForm.get("mchntName"));
request.setAttribute("othermMchntName", dyForm.get("othermMchntName"));
request.setAttribute("mchntType", dyForm.get("mchntType"));
request.setAttribute("mchntDirType", dyForm.get("mchntDirType"));
return IConstants.SUCCESS_KEY;
}
private MerchantModel formToModel(DynaValidatorForm df){
MerchantModel merModel=new MerchantModel();
merModel.setMchntid(StringUtil.convertNullToString(df.get("mchntId"))) ;//商户编号
merModel.setMchntname(StringUtil.convertNullToString(df.get("mchntName"))) ;//商户名称
merModel.setOthermMchntName(StringUtil.convertNullToString(df.get("othermMchntName"))) ;//手动输入的商户名称
merModel.setMchnttype(StringUtil.convertNullToString(df.get("mchntType"))) ;//商户下载类型
merModel.setMchntdirtype(StringUtil.convertNullToString(df.get("mchntDirType"))) ;//商户直充类型
return merModel;
}
}
连接数据库操作代码:
public static RowSetPage queryMerchant(MerchantModel merModel, int pageNum, int pageSize, Connection conn) throws Exception {
PagedStatement ps = null ;
StringBuffer sql = new StringBuffer() ;
sql.append("select m.mchntname , ");
sql.append("m.mchntid , ");
sql.append("m.mchntContact , ");
sql.append("m.mchntphone , ");
sql.append("m.MchntType , m.MchntdirType , ");
sql.append("a.mchntArea ");
sql.append("from m_merchant m , m_area a ");
sql.append(" where a.mchntArea = m.mchntArea ");
if (merModel.getMchntid()!= null && !"".equals(merModel.getMchntid().trim())) {
sql.append(" AND m.MchntID like '%").append(merModel.getMchntid()).append("%' ");
}
if (merModel.getMchntname()!= null && !"".equals(merModel.getMchntname().trim()) && !"0".equals(merModel.getMchntname().trim())) {
sql.append(" AND replace(m.mchntid,' ','') = '").append(merModel.getMchntname().trim()).append("' ");
}
if (merModel.getOthermMchntName()!= null && !"".equals(merModel.getOthermMchntName().trim()) && "0".equals(merModel.getMchntname().trim())) {
sql.append(" AND m.Mchntname like '%").append(merModel.getOthermMchntName()).append("%' ");
}
if (merModel.getMchnttype()!= null && !"".equals(merModel.getMchnttype().trim())) {
sql.append(" AND replace(m.mchntType,' ','') = '").append(merModel.getMchnttype().trim()).append("' ");
}
if (merModel.getMchntdirtype()!= null && !"".equals(merModel.getMchntdirtype().trim())) {
sql.append(" AND replace(m.MchntdirType,' ','') = '").append(merModel.getMchntdirtype().trim()).append("' ");
}
log.debug(sql.toString());
try {
ps = new PagedStatement(sql.toString(),pageNum,pageSize) ;
return ps.executeQuery(conn) ;
}catch(SQLException e){
log.error(" queryMerchant Error", e);
throw e;
}
finally{
sql = null;
if (ps != null) {
ps.close();
ps = null;
}
}
} --------------------编程问答-------------------- 谁能告诉我这个-Djdbc.connection.debug=true怎么用啊
--------------------编程问答-------------------- 嗨 ,哥们你这个问题后来怎么解决的? --------------------编程问答-------------------- 同求,我现在也遇到了这样的问题,但是不知道怎么解决!
补充:Java , Web 开发