Question

I'm running tomcat and have some jsp pages that display a subset of a table. I show 20 rows at a time on a single page. When the table has large amounts of data, the jsp page doesn't render. I'm guessing that the ResultSet is using a client side cursor. I've worked with ASP in the past, and we always used server side forward only cursors, and never had any problems with large amounts of data. Our database is oracle 10g.

How can I specify a server-side forward-only cursor in JDBC?

Was it helpful?

Solution

The oracle driver implements server-side cursors via the FetchSize property.

Unfortunately, JDBC doesn't explicitly allow for setting client vs server-side cursors, so different drivers implement it in different ways. Here are the other links that helped:

Fetch Size
Cursors
Oracle Driver

OTHER TIPS

Statement stmt = con.createStatement(ResultSet.TYPE_FORWARD_ONLY);
ResultSet rs = stmt.executeQuery(sql);

This should set it but apparently some drivers ignore it.

You could always try and set it again at ResultSet level.

rs.setFetchDirection(ResultSet.TYPE_FORWARD_ONLY);

Hope that helps.

Not quite answering the question, but have you considered explicitly adding paging to your SELECT query using ROWNUM or ROWNUMBER in your WHERE clause?

eg: for the second page of data, 20 element page size:

SELECT * 
  FROM MyDataObjects
  WHERE rownum > 20 AND rownum < 41

This would ensure that at most one page of records are returned, removing the large cursor issue.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top