smyers2003
asked on
JDBC - Need help getting a scrollable resultset!!!
Hello everyone,
I am having a problem with the following code, as I would like to have a scroll_insensitive resultset in order to use the resultset.getfirst() method:
.....
CallableStatement cs = myConnection.prepareCall(" call MY PROC",ResultSet.TYPE_SCROL L_SENSITIV E, ResultSet.CONCUR_UPDATABLE );
cs.registerOutParameter(1, OracleTypes.CURSOR);
cs.execute();
ResultSet rs = ((OracleCallableStatement) cs).getCur sor(1);
rs.beforeFirst(); --> This throws the following exception:
java.sql.SQLException: Invalid operation for forward only resultset : beforeFirst
Now, I am assuming that since I am declaring a new ResultSet object below where I declare my callablestatement, that this is the reason why my program thinks I have a forward-only resultset.
Can anyone suggest a way to make this resultset scroll_insensitive? I am drawing a blank here..
Thanks for any help!
I am having a problem with the following code, as I would like to have a scroll_insensitive resultset in order to use the resultset.getfirst() method:
.....
CallableStatement cs = myConnection.prepareCall("
cs.registerOutParameter(1,
cs.execute();
ResultSet rs = ((OracleCallableStatement)
rs.beforeFirst(); --> This throws the following exception:
java.sql.SQLException: Invalid operation for forward only resultset : beforeFirst
Now, I am assuming that since I am declaring a new ResultSet object below where I declare my callablestatement, that this is the reason why my program thinks I have a forward-only resultset.
Can anyone suggest a way to make this resultset scroll_insensitive? I am drawing a blank here..
Thanks for any help!
ASKER
Sorry, Kiranhk, my mistake - I did have scroll_insensitive at first and posted the wrong code here. When I do use scroll_insensitive at the top, it still doesn't work. I guess I could ask this question, then - how could I just create a resultset object from an oraclecallablestatement? I think this line here is the culprit, and it is returning a forward only resultset:
ResultSet rs = ((OracleCallableStatement) cs).getCur sor(1);
ResultSet rs = ((OracleCallableStatement)
ok, try this
cs.getResultSet()
cs.getResultSet()
ASKER
Hi Kiranhk,
If I do that, then, how would I make that resultset scroll_insensitive?
ResultSet rs = cs.getResultSet();
rs = ((OracleCallableStatement) cs).getCur sor(1);
Thanks for your help,
Shawn
If I do that, then, how would I make that resultset scroll_insensitive?
ResultSet rs = cs.getResultSet();
rs = ((OracleCallableStatement)
Thanks for your help,
Shawn
you need to use only one of them not both...
ResultSet rs = cs.getResultSet();
//rs = ((OracleCallableStatement) cs).getCur sor(1);
ResultSet rs = cs.getResultSet();
//rs = ((OracleCallableStatement)
ASKER
Hi Kiranhk,
I think I need to use the line of code already in there:
ResultSet rs = ((OracleCallableStatement) cs).getCur sor(1);
The proc I am calling returns a refcursor. When I try to use the cs.getResultSet it keeps coming back with nullPointerExceptions.
Thanks,
Shawn
I think I need to use the line of code already in there:
ResultSet rs = ((OracleCallableStatement)
The proc I am calling returns a refcursor. When I try to use the cs.getResultSet it keeps coming back with nullPointerExceptions.
Thanks,
Shawn
ok... do the previous one only but also post the stack trace and the full method code you are having..
//ResultSet rs = cs.getResultSet();
ResultSet rs = ((OracleCallableStatement) cs).getCur sor(1);
//ResultSet rs = cs.getResultSet();
ResultSet rs = ((OracleCallableStatement)
ASKER
Hi Kiranhk,
I am not getting much of a stack trace, even when I am catching everything with a throwable. I am connecting fine, etc. and the code is the same as originally listed:
CallableStatement cs = myConnection.prepareCall(" call MY PROC",ResultSet.TYPE_SCROL L_INSENSIT IVE, ResultSet.CONCUR_UPDATABLE );
cs.registerOutParameter(1, OracleTypes.CURSOR);
cs.execute();
//ResultSet rs = cs.getResultSet();
ResultSet rs = ((OracleCallableStatement) cs).getCur sor(1);
//jump to first record
rs.beforeFirst();
The nullpointer exception is being thrown after the execute takes place if I use cs.getResultSet().
The error "java.sql.SQLException: Invalid operation for forward only resultset : beforeFirst" is being thrown if I use ResultSet rs = ((OracleCallableStatement) cs).getCur sor(1); Either way, it looks as if I just need a way to set that damn rs as scrollable, eben though I am making the callablestatement scrollable.
The reason I want to get to the first record is that I am currently using rs.next (below the above code) to make my way through the recordset, and from my returned records it seems that I am always missing the very first record. Everything else works ok. I figured that by calling rs.beforeFirst() it would eliminate this problem, unless I am totally missing something obvious here.
Thanks
I am not getting much of a stack trace, even when I am catching everything with a throwable. I am connecting fine, etc. and the code is the same as originally listed:
CallableStatement cs = myConnection.prepareCall("
cs.registerOutParameter(1,
cs.execute();
//ResultSet rs = cs.getResultSet();
ResultSet rs = ((OracleCallableStatement)
//jump to first record
rs.beforeFirst();
The nullpointer exception is being thrown after the execute takes place if I use cs.getResultSet().
The error "java.sql.SQLException: Invalid operation for forward only resultset : beforeFirst" is being thrown if I use ResultSet rs = ((OracleCallableStatement)
The reason I want to get to the first record is that I am currently using rs.next (below the above code) to make my way through the recordset, and from my returned records it seems that I am always missing the very first record. Everything else works ok. I figured that by calling rs.beforeFirst() it would eliminate this problem, unless I am totally missing something obvious here.
Thanks
ok...
since beforeFirst will try to put put the cursor before the first row itself...
so instead of trying with rs.beforeFirst() try
rs.first()
then if there is any first row then you can check out your scrollable things...
since beforeFirst will try to put put the cursor before the first row itself...
so instead of trying with rs.beforeFirst() try
rs.first()
then if there is any first row then you can check out your scrollable things...
ASKER
;-) Yes, I already tried that a while ago before I posted here, but it had the same result:
java.sql.SQLException: Invalid operation for forward only resultset : first
This is frustrating! Should be a simple fix! Very strange and I have a feeling that this is something obvious that I am missing...
java.sql.SQLException: Invalid operation for forward only resultset : first
This is frustrating! Should be a simple fix! Very strange and I have a feeling that this is something obvious that I am missing...
ASKER
Increased the points grab....
ok, got the problem with this..
Oracle Ref Cursors are not scrollable... so you cannot do that it seems.
check out this documentation...
https://cwisdb.cc.kuleuven.ac.be/ora10doc/java.101/b10979/oraint.htm#i1063951
Oracle Ref Cursors are not scrollable... so you cannot do that it seems.
check out this documentation...
https://cwisdb.cc.kuleuven.ac.be/ora10doc/java.101/b10979/oraint.htm#i1063951
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Kiranhk,
Thank you very much for all of your efforts - I figured out another solution. Maybe talk to you again on the board sometime!
Thanks
Shawn
Thank you very much for all of your efforts - I figured out another solution. Maybe talk to you again on the board sometime!
Thanks
Shawn
ResultSet.TYPE_SCROLL_INSE
check this out
http://javaalmanac.com/egs/java.sql/MoveCursor.html