2016-07-04 73 views
0

我想要計算在Oracle BBDD上返回函數的行數。我在其他一些問題中看到過(例如:rs.last() gives Invalid operation for forward only resultset : last),需要添加ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY可調用語句resultset.last()在java中拋出一個異常

我已經試過ResultSet.TYPE_SCROLL_INSENSITIVE,也ResultSet.TYPE_SCROLL_SENSITIVE ...沒有結果。我仍然得到相同的無效操作異常。

我失蹤了什麼?

繼承人我的代碼:

String call = "{ ? = call MyProcedure (?) }"; 
CallableStatement cstmt= conn.prepareCall(call, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); 
cstmt.setString(2,"param 1"); 
cstmt.registerOutParameter(1, OracleTypes.CURSOR); 

cstmt.execute(); 
ResultSet rset = (ResultSet)cstmt.getObject(1); 
rset.last(); //Exception comes here 
int rowsnumber = rset.getRow(); 

感謝。

編輯:

正如評論說,我第一次添加了Oracle功能我打電話:

create or replace FUNCTION MyProcedure 
(IdC IN VARCHAR2 
) 
RETURN sys_refcursor 
IS 
    c_result sys_refcursor; 
BEGIN 
    OPEN c_result FOR SELECT name, properties FROM city WHERE name = IdC; 
    RETURN c_result; 
END; 

而且堆棧跟蹤:

Stack: java.sql.SQLException: Operación no válida para el juego de resultados de sólo reenvío : last 
    at oracle.jdbc.driver.InsensitiveScrollableResultSet.last(InsensitiveScrollableResultSet.java:646) 
    at MyPackage.CoreWS.ExProcedure(CoreWS.java:58) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:498) 
    at weblogic.wsee.jaxws.WLSInstanceResolver$WLSInvoker.invoke(WLSInstanceResolver.java:120) 
    at weblogic.wsee.jaxws.WLSInstanceResolver$WLSInvoker.invoke(WLSInstanceResolver.java:93) 
    at com.sun.xml.ws.server.InvokerTube$2.invoke(InvokerTube.java:149) 
    at com.sun.xml.ws.server.sei.SEIInvokerTube.processRequest(SEIInvokerTube.java:88) 
    at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:1136) 
    at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:1050) 
    at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:1019) 
    at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:877) 
    at com.sun.xml.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:419) 
    at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:868) 
    at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:422) 
    at com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:169) 
    at weblogic.wsee.jaxws.WLSServletAdapter.handle(WLSServletAdapter.java:229) 
    at weblogic.wsee.jaxws.HttpServletAdapter$AuthorizedInvoke.run(HttpServletAdapter.java:667) 
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:368) 
    at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:163) 
    at weblogic.wsee.util.ServerSecurityHelper.authenticatedInvoke(ServerSecurityHelper.java:108) 
    at weblogic.wsee.jaxws.HttpServletAdapter$3.run(HttpServletAdapter.java:286) 
    at weblogic.wsee.jaxws.HttpServletAdapter.post(HttpServletAdapter.java:295) 
    at weblogic.wsee.jaxws.JAXWSServlet.doRequest(JAXWSServlet.java:128) 
    at weblogic.servlet.http.AbstractAsyncServlet.service(AbstractAsyncServlet.java:103) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) 
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:286) 
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:260) 
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:137) 
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:350) 
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:247) 
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3679) 
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3649) 
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:326) 
    at weblogic.security.service.SecurityManager.runAsForUserCode(SecurityManager.java:197) 
    at weblogic.servlet.provider.WlsSecurityProvider.runAsForUserCode(WlsSecurityProvider.java:203) 
    at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:71) 
    at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2433) 
    at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2281) 
    at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2259) 
    at weblogic.servlet.internal.ServletRequestImpl.runInternal(ServletRequestImpl.java:1686) 
    at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1646) 
    at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:270) 
    at weblogic.invocation.ComponentInvocationContextManager._runAs(ComponentInvocationContextManager.java:348) 
    at weblogic.invocation.ComponentInvocationContextManager.runAs(ComponentInvocationContextManager.java:333) 
    at weblogic.work.LivePartitionUtility.doRunWorkUnderContext(LivePartitionUtility.java:54) 
    at weblogic.work.PartitionUtility.runWorkUnderContext(PartitionUtility.java:41) 
    at weblogic.work.SelfTuningWorkManagerImpl.runWorkUnderContext(SelfTuningWorkManagerImpl.java:640) 
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:406) 
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:346) 
+2

追加堆棧跟蹤 – Jens

+0

試試這件? [轉到jdbc中結果集的最後一行](http://stackoverflow.com/questions/10659083/go-to-last-row-from-result-set-in-jdbc-with-sql-server) –

+0

它真的無效操作或SQLFeatureNotSupportedException – Fildor

回答

0

的移動能力其僅向前遊標是ResultSet的默認行爲,並且是僅實現了JDBC 1.0 API的驅動程序的唯一光標移動。這種結果集的類型爲ResultSet.TYPE_FORWARD_ONLY,被稱爲僅前向結果集。

如果驅動程序在JDBC 2.0核心API中實現光標移動方法,則其結果集可以滾動。可滾動結果集的遊標可以向前和向後移動以及移動到特定行。以下方法將光標向後移動到第一行,移動到最後一行,移動到特定的行號,從當前行移動到指定數量的行,依此類推:previous,first,last,absolute,relative,afterLast ,並在之前。

您能否確認您的API版本?

參考:Result set

另外,作爲由Mark Rotteveel的意見建議,你爲什麼不使光標作爲outparameter拿去明確,而不是在函數中使用的回報,並驗證其是否工作?