title: Prepared Statement and Statement/Query Caching
body: <p>I am trying to understanding if Statement caching is useful in case of parametrized prepared statements.</p>
  
  <p>As per my understanding</p>
  
  <ul>
  <li>If I use caching,  then query will cached based on its 'String'. </li>
  <li>In this case, if a query has different values of parameter then it is a different / new statement/string w.r.t. caching.</li>
  <li>Also, when parameters change, the results also  change.</li>
  <li>Since prepared statements are parameterized, is it really useful to use caching in this case. </li>
  </ul>
  
  <p>I am using JDBC/Snaq DB Pool/ MySQL database.</p>
  
  <p>Statement Caching here is referred to two different cases:</p>
  
  <ul>
  <li>JAVA: Snaq DB pool provided ConnectionCache class which facilitates caching of Statements.</li>
  <li>MySQL: DB also provided ways to cache query and result.<a href="http://dev.mysql.com/doc/refman/5.1/en/query-cache.html" rel="nofollow">http://dev.mysql.com/doc/refman/5.1/en/query-cache.html</a></li>
  </ul>
  
  <p>My confusion is simple:</p>
  
  <ul>
  <li>If I were to search a Query / Corresponding Result in a Cache, I will search it on basis of String comparison. </li>
  <li>If parameter values change, so does String of query.</li>
  <li>This will result in to different entries in cache for same query with different set of values of parameters. </li>
  </ul>
  
  <p>Hope I clarify my question.    </p>