问题描述
在重复提交或多客户操作时老出现DSRA9110E:Statementisclosed这个错误,大大们帮忙看下行不。谢谢了!下面是我调用的方法,入口为selRefForProNo,error是在执行select()方法是出现的:publicclassReservationExecControllerextendsReservationBaseController{publicReservationExecController(ActionMappingmapping,HttpServletRequestrequest,HttpServletResponseresponse,ConnectionManagerconnMgr,ActionMessageManagermessageMgr){super(mapping,request,response,connMgr,messageMgr);//TODO自动生成的构造函数存根}publicList<ReservationNodepad>selReservationNodepad(ReservationNodepadreservationNodepad)throwsException{ReservationExecManagerreservationExecManager=newReservationExecManager(connMgr,messageMgr);returnreservationExecManager.select(reservationNodepad);}publicList<GenericCode>selGenericCode(GenericCodegenericCode)throwsException{ReservationExecManagerreservationExecManager=newReservationExecManager(connMgr,messageMgr);returnreservationExecManager.select(genericCode);}publicList<ReservationSchedule>selReservationSchedule(ReservationSchedulereservationSchedule)throwsException{ReservationExecManagerreservationExecManager=newReservationExecManager(connMgr,messageMgr);reservationSchedule.setActiveIdx(ReservationParameter.ACTIVEIDX_Y);returnreservationExecManager.select(reservationSchedule);}publicList<Proposal>selProposal(Proposalproposal)throwsException{ReservationExecManagerreservationExecManager=newReservationExecManager(connMgr,messageMgr);returnreservationExecManager.select(proposal);}publicList<ReservationTransaction>selReservationTransaction(ReservationTransactionreservationTransaction)throwsException{ReservationExecManagerreservationExecManager=newReservationExecManager(connMgr,messageMgr);returnreservationExecManager.select(reservationTransaction);}publicList<ReservationStatus>selReservationStatus(ReservationStatusreservationStatus)throwsException{ReservationExecManagerreservationExecManager=newReservationExecManager(connMgr,messageMgr);returnreservationExecManager.select(reservationStatus);}publicbooleanselRefForProNo(ReservationExecFormreservationExecForm)throwsException{booleanbool=true;List<Proposal>proList=selProposal(reservationExecForm.getProposal());bool=isValiProNo(proList);bool=bool&&ReservationParameter.LOAN_STATUS_SIGN.equals(proList.get(0).getStatus());if(bool){reservationExecForm.setProposal(proList.get(0));selReservationExecForm(reservationExecForm);ReservationLockingreservationLocking=newReservationLocking();reservationLocking.setProposalNo(reservationExecForm.getProposal().getProposalNo());List<ReservationLocking>rlList=selReservationLock(reservationLocking);if(rlList.size()>0&&!request.getSession().getAttribute("username").toString().equals(rlList.get(0).getCreateBy())){reservationExecForm.setIsLock(true);reservationExecForm.setReservationLocking(rlList.get(0));}else{bool=bool&&addReservationLocking(reservationLocking)==1?true:false;reservationExecForm.setIsLock(false);reservationExecForm.setReservationLocking(reservationLocking);}getReservationExecList(reservationExecForm);}returnbool;}publicbooleanselReservationExecForm(ReservationExecFormreservationExecForm)throwsException{booleanbool=true;ReservationNodepadreservationNodepad=newReservationNodepad();reservationNodepad.setProposalNo(reservationExecForm.getProposal().getProposalNo());Util.clearList(reservationExecForm.getRnList()).addAll(selReservationNodepad(reservationNodepad));for(ReservationNodepadrn:reservationExecForm.getRnList()){if(rn.getCreatedDate()!=null){rn.getRnd().setCreatedDate(Util.DateStringConverter(rn.getCreatedDate(),ReservationParameter.DATE_FORMAT_ITEM));}if(rn.getLastUpdatedDate()!=null){rn.getRnd().setLastUpdatedDate(Util.DateStringConverter(rn.getLastUpdatedDate(),ReservationParameter.DATE_FORMAT_ITEM));}}ReservationSchedulereservationSchedule=newReservationSchedule();reservationSchedule.setBranchCode(reservationExecForm.getProposal().getBranchCode());Util.clearList(reservationExecForm.getRsList()).addAll(selReservationSchedule(reservationSchedule));GenericCodegenericCode=newGenericCode();genericCode.setCategory(ReservationParameter.CATEGORY);List<GenericCode>gcList=selGenericCode(genericCode);for(GenericCodegc:gcList){if(gc.getGroupCode()==null||"".equals(gc.getGroupCode())){reservationExecForm.getGcParentList().add(gc);}else{reservationExecForm.getGcChildList().add(gc);}}reservationExecForm.getReservationStatus().setActiveIdx(ReservationParameter.ACTIVEIDX_Y);reservationExecForm.getReservationStatus().setProposalNo(reservationExecForm.getProposal().getProposalNo());List<ReservationStatus>rsList=selReservationStatus(reservationExecForm.getReservationStatus());reservationExecForm.setReservationStatus(rsList.size()==1?rsList.get(0):null);reservationExecForm.getReservationTransaction().setActiveIdx(ReservationParameter.ACTIVEIDX_Y);reservationExecForm.getReservationTransaction().setProposalNo(reservationExecForm.getProposal().getProposalNo());List<ReservationTransaction>rtList=selReservationTransaction(reservationExecForm.getReservationTransaction());reservationExecForm.setReservationTransaction(rtList.size()==1?rtList.get(0):null);if(rtList.size()>0){DatereserveDate=reservationExecForm.getReservationTransaction().getReserveDate();reservationExecForm.setReserveDate(reserveDate==null?null:Util.DateStringConverter(reserveDate,ReservationParameter.DATE_FORMAT_NOITEM));}else{reservationExecForm.setReserveDate(null);}Collections.sort(reservationExecForm.getRsList());returnbool;}
解决方案
解决方案二:
publicclassBaseManager{publicConnectionManagerconnMgr=null;publicstaticLoggerlogger=Parameter.logger;protectedActionMessageManagermessageMgr=null;public<TextendsObject>List<T>select(Tentity)throwsException{List<T>list=newArrayList<T>();Classcls=entity.getClass();StringtblName=Util.getOracleName(cls.getSimpleName());Connectionconn=null;PreparedStatementps=null;ResultSetrs=null;StringBuffersql=newStringBuffer("Select");StringBuffersql1=newStringBuffer();List<Object>valueList=newArrayList<Object>();Field[]fields=cls.getDeclaredFields();for(Fieldfield:fields){StringproName=field.getName();if(Util.DATA_TYPE_MAP.containsKey(field.getType().getName())){if(Parameter.DATA_STATUS.equals(field.getType().getName())){sql.append("to_char(").append(Util.getOracleName(proName));sql.append(",'yyyy-mm-ddhh24:mi:ss')").append(Util.getOracleName(proName));sql.append(",");}else{sql.append(Util.getOracleName(proName)).append(",");}}Objectvalue=Util.getProValue(entity,field);if(Util.DATA_TYPE_MAP.containsKey(field.getType().getName())&&value!=null&&!"".equals(value)){if(!field.getType().getName().equals(field.getType().getSimpleName())){if(Parameter.DATA_STATUS.equals(field.getType().getName())){sql1.append("and").append("to_char(").append(Util.getOracleName(proName));sql1.append(",'yyyy-mm-dd')").append("=?");value=Util.DateStringConverter((Date)value,"yyyy-MM-dd");}else{sql1.append("and").append(Util.getOracleName(proName)).append("=?");}valueList.add(value);}}}sql=sql.delete(sql.length()-1,sql.length());sql.append("from").append(tblName).append("where1=1");sql.append(sql1);try{conn=connMgr.getConnection();ps=conn.prepareStatement(sql.toString());for(inti=0;i<valueList.size();i++){ps.setObject(i+1,valueList.get(i));}rs=ps.executeQuery();while(rs.next()){ObjectentityObj=Class.forName(cls.getName()).newInstance();for(Fieldfield:fields){if(Util.DATA_TYPE_MAP.containsKey(field.getType().getName())){Objectvalue=rs.getObject(Util.getOracleName(field.getName()));if(Parameter.DATA_STATUS.equals(field.getType().getName())&&value!=null){value=Util.DateStringConverter(value.toString(),"yyyy-MM-ddHH:mm:ss");}Util.setProValue(entityObj,field,value);}}list.add((T)entityObj);}}catch(Exceptione){e.printStackTrace();logger.error("selectSqlexception(table"+tblName+"):"+e);throwe;}finally{try{if(rs!=null||!rs.isClosed()){rs.close();rs=null;}if(ps!=null||!ps.isClosed()){ps.close();ps=null;}}catch(SQLExceptione){e.printStackTrace();}}returnlist;}}
解决方案三:
BaseManager类是ReservationExecManager类的父类,在调试时发现某些时候执行BaseManager类中select()的rs=ps.executeQuery()时就会出现DSRA9110E:Statementisclosed,我一开始以为是多线程的问题,在select(),selRefForProNo()方法前加了synchronized,但是没有效果。大大们帮忙看看咯,我研究一天了都。谢谢!!!
解决方案四:
该回复于2011-02-18 09:23:26被版主删除
解决方案五:
大大们帮忙看看啊,谢谢!
解决方案六:
搜了一下,网上说是连接池问题。你试过直连数据库没有?
解决方案七:
try{if(rs!=null||!rs.isClosed()){rs.close();rs=null;}if(ps!=null||!ps.isClosed()){ps.close();ps=null;}}catch(SQLExceptione){e.printStackTrace();}
楼主,不要一遇到try就close,先要看还有用没。希望对你有帮助
解决方案八:
引用6楼woshigaoshou980的回复:
Javacodetry{if(rs!=null||!rs.isClosed()){rs.close();rs=null;}if(ps!=null||!ps.isClosed()){ps.close();ps=null;}}catch(SQLExceptione){e.printStackTrace();}楼主……
我是把结果集写入list后,在finally块中关闭的rs和ps,不是很明白你所说的还有用没的意思
解决方案九:
ResultSet和PreparedStatement会自动失效吗?
解决方案十:
怎么没人回呢?自己顶下!