This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Oracle/OAS and the fly likes Problems with functions and absolute cursor control. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Oracle/OAS
Bookmark "Problems with functions and absolute cursor control." Watch "Problems with functions and absolute cursor control." New topic

Problems with functions and absolute cursor control.

Clay Graham

Joined: Dec 01, 2003
Posts: 3
I am attempting to write a paginated results class, which will allow a web user to make paginated queries to the preparedCall and return a OracleTypes.CURSOR object. The user session would then store the current position and only retrieve results associated with the current page using the absolute function. This is basic stuff, I know, but I cant find out how to do it.
We are using the good'ol thin driver with Oracle8i and JDK1.4, which would *seem* to me to support the JDBC2.0 functionality of rs.absolute(2), but I am getting an error: Invalid operation for forward only resultset : absolute which seems to me to be a JDBC 1.0 issue. wierd.
Here is the base code:
RETURN Types.ref_cursor
title_cursor types.ref_cursor;
title_search varchar2(200);
v_query varchar2(500);
ref_title varchar2(500);
ref_docnum varchar2(32);

title_search :='%' || v_title || '%';
v_query:='SELECT TITLE1, DOCUMENT_NUMBER FROM references where title1 like :1 ';

OPEN title_cursor FOR
v_query using title_search;

RETURN title_cursor;


import oracle.jdbc.OracleTypes;
import java.util.*;
import java.sql.*;
import javax.sql.*;
* @author cwgraham
public class TestStoredProc {

/** Creates a new instance of TestStoredProc */
public TestStoredProc() {

* @param args the command line arguments
public static void main(String[] args) {
Connection conn = null;
String JDBC_CONNECTION_STRING="jdbc racle:thin:@host:1521:sid";
String username= "user";
String password= "password";
conn = DriverManager.getConnection(JDBC_CONNECTION_STRING,username,password);
if(conn.getMetaData().supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE))
System.out.println("options concurrency are supported");

if(conn.getMetaData().supportsResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE)) {
System.out.println("options type are supported");

String query="{ call ? := getdocnum(?) }";
CallableStatement stmt = conn.prepareCall(query, java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE, java.sql.ResultSet.CONCUR_READ_ONLY);
// register the type of the out param - an Oracle specific type
stmt.registerOutParameter(1, OracleTypes.CURSOR);
// set the in param
stmt.setString(2,"AFRICANS"); //title
// execute and retrieve the result set
ResultSet rs = (ResultSet)stmt.getObject(1);

int start=4;
int end=8;
//int i=1;
for(int i=start; i<=end; i++)
System.out.println("#"+i+":"+rs.getString("DOCUMENT_NUMBER")+": "+rs.getString("TITLE1"));

catch(ClassNotFoundException cnfex)
catch(SQLException sex)


So it responds as if it was JDBC 1.0, even though I have verified that it
supports cursor control:
options concurrency are supported
options type are supported
Invalid operation for forward only resultset : absolute
So I would love to solve this problem, at least I would have a first step to a solution, but the next question is: shouldn't there be an even better way? It would seem to me in this web world of ConnectionPools and web applications with session, that we could close the connection, save some sort of session id in the web application session state, and come back to this cursor using some type of oracle session id when we open the connection. Do you know how this may be possible?
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1121

A crosspost! Well, I did answer this exact same question that you posted to the JDBC forum.
Good Luck,
It is sorta covered in the JavaRanch Style Guide.
subject: Problems with functions and absolute cursor control.
Similar Threads
Stored procedure which returns array
SQLException Cursor Closed
AbstractTableModel NullPointerException
Problems with functions and absolute cursor control.
How to obtain a resultset using a stored procedure