11

I want to use caching with JDBC.
How can I achieve that?
Are there any built-in mechanisms or do I have to use 3rd party solutions?
What is best practise for caching with JDBC.

Thank You, Jack

EDITED: what about CachedRowSet? http://docs.oracle.com/javase/tutorial/jdbc/basics/cachedrowset.html

Jack Mszczynski
  • 221
  • 2
  • 3
  • 7
  • 2
    there's no answer. Frankly, there's no question: you can cache connections, `PreparedStatement`s, query results, etc., etc. For each type of caching, you'll get a different approach. – alf Dec 04 '11 at 16:05
  • It depends on what exactly you want to cache. See http://www.javaperformancetuning.com/tips/jdbc_caching.shtml – ziggy Dec 04 '11 at 16:06
  • @alf, can you cache connections? and what do you do with cached connections ? :-) I guess you meant you could pool connections :-) – aishwarya Dec 04 '11 at 16:07
  • @aishwarya I don't think ranting on terminology is going to get us anywhere :) Point is, there are levels and levels of caching, and focusing on JDBC means missing the point. – alf Dec 04 '11 at 16:11
  • @alf, sorry, no offense intended really! apologies if it felt that way. btw, caching and pooling are 2 different things and I won't want Jack to confuse that he could cache a connection (I have seen people try that!!). I am sure you would understand and agree that caching a connection is one not possible, second meaningless. I agree the question needs to be clarified on what level of caching is being sought, I assumed it to be data - my bad!! – aishwarya Dec 04 '11 at 16:16
  • I was thinking qbout caching query results, I am sorry if my question wasn't precise. – Jack Mszczynski Dec 04 '11 at 16:22
  • @aishwarya not necessary data. For example, `PreparedStatement`s are "cached", not "pooled"—still, they are not only "data," as there's often a server state involved. So it's more of a terminology question. – alf Dec 04 '11 at 16:27
  • @JackMszczynski profile first, cache when you know you do the same work way too many times. `ehcache` is a decent option indeed. – alf Dec 04 '11 at 16:28

2 Answers2

1

try ehcache. JDBC does not have caching by itself, but ehcache is pretty good. if you want a more robust cluster safe cache, try oracle coherence. I typically do not put a cache at first and run some performance tests, only if tests indicate a need for a cache is when I put one.

aishwarya
  • 1,970
  • 1
  • 14
  • 22
0

There is few options now:

Emmanuel Keller
  • 3,384
  • 1
  • 14
  • 16