问题描述
代码如下publicString[]querySelectedColumnName(Stringname,Longuserid)throwsException{Connectionconn=null;Statementstm=null;Stringsql="";String[]selectcloumn=newString[]{};Stringscloumn="";ResultSetrs=null;try{conn=this.getHibernateTemplate().getSessionFactory().openSession().connection();stm=conn.createStatement();sql+="selectSELECTCOLUMNNAMEfromt_diywhereTABLENAME='"+name+"'andUSERID="+userid+"andrownum<=1";System.out.println("sql:"+sql);rs=stm.executeQuery(sql);if(rs!=null&&rs.next()){scloumn+=rs.getString(1);selectcloumn=scloumn.split(",");}}catch(Exceptionex){ex.printStackTrace();}finally{try{if(rs!=null){rs.close();rs=null;}if(stm!=null){stm.close();stm=null;}if(conn!=null){try{conn.close();}catch(SQLExceptione){System.err.println(e.getMessage());}}}catch(SQLExceptione){e.printStackTrace();}}returnselectcloumn;}一开始报”用尽的Resultset“if(rs.next())=》if(rs!=null&&rs.next())又开始报java.lang.NullPointerExceptionatoracle.jdbc.driver.OracleStatement.clearDefines(OracleStatement.java:1176)atoracle.jdbc.driver.OracleStatement.end_of_result_set(OracleStatement.java:3150)atoracle.jdbc.driver.OracleResultSetImpl.internal_close(OracleResultSetImpl.java:1474)atoracle.jdbc.driver.OracleResultSetImpl.close(OracleResultSetImpl.java:92)atorg.apache.commons.dbcp.DelegatingResultSet.close(DelegatingResultSet.java:151)atcom.wprss.dao.impl.UserDAOImpl.queryColumnName(UserDAOImpl.java:494)atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)atjava.lang.reflect.Method.invoke(Method.java:585)atorg.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:287)atorg.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:181)atorg.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:148)atorg.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)atorg.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)atorg.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176)at$Proxy2.queryColumnName(UnknownSource)atcom.wprss.action.UserAction.showColumnName(UserAction.java:729)atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)atjava.lang.reflect.Method.invoke(Method.java:585)atorg.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:274)atorg.apache.struts.actions.DispatchAction.execute(DispatchAction.java:194)atorg.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)atorg.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)atorg.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)atorg.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:709)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:802)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)atcom.wprss.util.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:38)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)atcom.wprss.util.RightFilter.doFilter(RightFilter.java:35)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)atcom.wprss.util.NoCacheFilter.doFilter(NoCacheFilter.java:23)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)atorg.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)atorg.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)atorg.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)atorg.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)atorg.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)atorg.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)atorg.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:831)atorg.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:639)atorg.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1203)atjava.lang.Thread.run(Thread.java:595)sql肯定没问题!谢
解决方案
解决方案二:
执行一两次没问题,多执行几次这方法后就会报错!为什么呢?该关的我都关了啊
解决方案三:
while(rs.hasNext())
解决方案四:
引用2楼xiaoye2892的回复:
while(rs.hasNext())
我铁定就返回一条结果也得用while吗是这样吗
解决方案五:
只有一条结果可以不用while。你把你拼装的sql贴出来看看。引用3楼wsonline的回复:
引用2楼xiaoye2892的回复:while(rs.hasNext())我铁定就返回一条结果也得用while吗是这样吗
解决方案六:
sql="HQl"语句试试....
解决方案七:
if(rs!=null&&rs.next()){scloumn+=rs.getString(1);}selectcloumn=scloumn.split(",");
解决方案八:
close就close了。就别再设置成Null了。。