sahar
sahar

Reputation: 569

caching sql result set in java

I know that caching the resultset of frequently used sql statements is better for the performance I am searching about the best way to cache sql result set in java. I found some codes but, it requires adding new jar files to netbeans. Can anybody help me how can do that without needing to additional apis?

Upvotes: 0

Views: 3147

Answers (3)

Alfred
Alfred

Reputation: 61793

You should cache the data only. I would advise you to use an external api because you will probably also need to evict old data from cache(to prevent from using to much memory).

Using guave:

ConcurrentMap _continueContexts = new MapMaker() .expiration(10, TimeUnit.SECONDS) .makeMap();

P.S: You should something like maven to manage your dependencies.

Upvotes: 0

user328898
user328898

Reputation:

You could make a linked list of results. With the cache trigger pointing to the start of the list. Since linked lists act like a wrapper around whatever you want you can make the results as generic as you want. This won't require another api but you will have to implement this all on your own and hopefully you understand why we don't like reinventing the wheel.

Upvotes: 0

Arne Burmeister
Arne Burmeister

Reputation: 20614

You should cache the resulting objects, not the result sets, because the ResultSet has a reference to the connection (via the statement) which often hold an open database connection or is no longer usable after the connection has been closed!

Upvotes: 6

Related Questions