File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Caching Database Rows Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Caching Database Rows" Watch "Caching Database Rows" New topic

Caching Database Rows

Alec Lee
Ranch Hand

Joined: Jan 28, 2004
Posts: 569
Just wondering if there is any built-in support of caching database rows in JDBC. Currently, if there is some rows to be accessed repeatedly, to reduce the number of SQL calls, I will manually create a Map containing the rows with the Map's key=PK of the table. But maintaining the cache manually looks tedious so just want to know if JDBC already providing help in this area.

Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33132

JDBC doesn't provide caching built in. The database itself does caching, but then you still have to make a call to the database tier.

Your custom cache is a good way to go. You could do it as a wrapper around JDBC so all the code is in one place.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1082


you can opt for CachedRowset, It is basically a disconnection rowset


Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
steve souza
Ranch Hand

Joined: Jun 26, 2002
Posts: 862
I have cached ResultSets as arrays: Object[][].

One advantage of this approach is that I also have an API that allows you to easily query and sort the array that is in cache (A limited sql syntax but still very handy).

For more info go to There are a couple powerpoints to the left that discuss ArraySQL. I also have a class called ResultSetConverter that puts a ResultSet into an Object[][].
[ May 26, 2005: Message edited by: steve souza ] - a fast, free open source performance tuning api.
JavaRanch Performance FAQ
I agree. Here's the link:
subject: Caching Database Rows
jQuery in Action, 3rd edition