• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problems with functions and absolute cursor control.

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 classes12.zip 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:
CREATE OR REPLACE FUNCTION "GETDOCNUM" (v_title IN VARCHAR2)
RETURN Types.ref_cursor
AS
title_cursor types.ref_cursor;
title_search varchar2(200);
v_query varchar2(500);
ref_title varchar2(500);
ref_docnum varchar2(32);

BEGIN
title_search :='%' || v_title || '%';
v_query:='SELECT TITLE1, DOCUMENT_NUMBER FROM references where title1 like :1 ';
dbms_output.put_line(v_query);

OPEN title_cursor FOR
v_query using title_search;


RETURN title_cursor;

END;
/

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) {
try{
Connection conn = null;
String JDBC_CONNECTION_STRING="jdbc racle:thin:@host:1521:sid";
String username= "user";
String password= "password";
Class.forName("oracle.jdbc.driver.OracleDriver");
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
stmt.execute();
ResultSet rs = (ResultSet)stmt.getObject(1);

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

}
catch(ClassNotFoundException cnfex)
{
System.out.println("error:"+cnfex.getMessage());
}
catch(SQLException sex)
{
System.out.println("error:"+sex.getMessage());
}

}

}
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?
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Clay,
A crosspost! Well, I did answer this exact same question that you posted to the JDBC forum.
Good Luck,
Avi.
 
Are you okay? You look a little big. Maybe this tiny ad will help:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic