Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: 结果集没有当前行。

十一月 27, 2018 8:59:31 下午 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet [ShoppingServlet] in context with path [/JavaWebProgram] threw exception
java.lang.RuntimeException: com.microsoft.sqlserver.jdbc.SQLServerException: 结果集没有当前行。
at cn.itcast.Servlet.com.ShoppingServlet.doGet(ShoppingServlet.java:23)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:800)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol C o n n e c t i o n H a n d l e r . p r o c e s s ( A b s t r a c t P r o t o c o l . j a v a : 806 ) a t o r g . a p a c h e . t o m c a t . u t i l . n e t . N i o E n d p o i n t ConnectionHandler.process(AbstractProtocol.java:806) at org.apache.tomcat.util.net.NioEndpoint ConnectionHandler.process(AbstractProtocol.java:806)atorg.apache.tomcat.util.net.NioEndpointSocketProcessor.doRun(NioEndpoint.java:1498)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor W o r k e r . r u n ( U n k n o w n S o u r c e ) 加 粗 样 式 a t o r g . a p a c h e . t o m c a t . u t i l . t h r e a d s . T a s k T h r e a d Worker.run(Unknown Source)加粗样式 at org.apache.tomcat.util.threads.TaskThread Worker.run(UnknownSource)atorg.apache.tomcat.util.threads.TaskThreadWrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: 结果集没有当前行。_第1张图片
原因:结果集rs的位置初始时位于第一条记录的前面,即为0。所以当用if来判断时,会出现结果集当前行为空。
这是ResultSet指向的问题,ResultSet取值后,指针默认指向index为-1的前一个元素,
即ResultSet中第一个元素的前面,这时指针默认指向是不存在元素的,因此出现错误。必须调用.next()函数才能,对ResultSet进行遍历。

作者:luoxia0805
来源:CSDN
原文:https://blog.csdn.net/luoxia0805/article/details/41957631
版权声明:本文为博主原创文章,转载请附上博文链接!

你可能感兴趣的:(Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: 结果集没有当前行。)