This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I am using stored procedures with an Oracle database to return cursors. However, the cursors that it returns are always TYPE_FORWARD_ONLY. I am trying to set the type to be TYPE_SCROLL_INSENSTIVE, but it does not seem to be working.
Here is the sample code I am using
In the above example, rs is always TYPE_FORWARD_ONLY. Anyone know how to fix this?
Kevin [ March 13, 2006: Message edited by: Kevin Conaway ]
I don't know how to fix this, mostly because using Oracle scrollable ResultSets are implemented by caching the entire ResultSet in Java memory; the ResultSets my application has are often too big for that. Also, last I checked, ResultSet.last() transfered every row of a scrollable result to get to the end.
How do you handle large result sets with oracle? I was hoping to be able to index or page into the result set to retrieve the items I wanted. I definitely do not want to read every row sequentially to get to where I want.
Second, a well-designed web application should be able to handle display of an infinitely large ResultSet; the limit should be the memory of the client's browser and the client's patience, not some arbitrary limit in your code or the memory limit of your JVM. This is accomplished by "streaming" the data through the application; data is read, processed, and output to the response, row by row, with only buffered chunks of the ResultSet and the response in memory at once, not all of either of them. (A few J2EE servers do not normally stream the response, requiring a periodic flush(), but most do).
Joined: Jan 27, 2006
I was hoping to for something less invasive that does not require the modifications of stored procedures.
Also, if I need to know the total number of rows available, is SELECT COUNT(ID) FROM DATA the best way to handle this?
It is the typical way to go, and I think the only way to go in situations where you have any kind of where clause to specify a subset. If you literally want to know the entire table size and don't care about supporting multiple database vendors in your code, there is Oracle metadata that will tell you how many rows there are in the table.
I haven't compared the timings of the two. Conceptually the metadata approach would be constant time and the count approach linear time, but I wouldn't be surprised if you found Oracle query processing spotted such an obvious attempt to measure table size and internally used the metadata anyways.