title: stored procedures as queries: CallableStatement vs. PreparedStatement
body: <p><a href="http://www.postgresql.org/docs/7.4/static/jdbc-callproc.html">PostgreSQL documentation</a> recommends using a <a href="http://download.oracle.com/javase/6/docs/api/java/sql/CallableStatement.html"><code>CallableStatement</code></a> to call stored procedures.</p>
  
  <p>In the case of a stored procedure that returns a rowset, what are the differences between using <code>CallableStatement</code>:</p>
  
  <pre><code>String callString = "{ call rankFoos(?, ?) }";
  CallableStatement callableStatement = con.prepareCall(callString);
  callableStatement.setString(1, fooCategory);
  callableStatement.setInt(2, minimumRank);
  ResultSet results = statement.executeQuery();
  </code></pre>
  
  <p>And using a regular <a href="http://download.oracle.com/javase/6/docs/api/java/sql/PreparedStatement.html"><code>PreparedStatement</code></a>:</p>
  
  <pre><code>String queryString = "SELECT FooUID, Rank FROM rankFoos(?, ?);";
  PreparedStatement preparedStatement = connection.prepareStatement(queryString);
  preparedStatement.setString(1, fooCategory);
  preparedStatement.setInt(2, minimumRank);
  ResultSet results = statement.executeQuery();
  </code></pre>
  
  <p>As I understand, <code>CallableStatement</code> offers a language-agnostic way of calling stored procedures. This doesn't matter to me though, since I know I'm using PostgreSQL. As far as I can see, the obvious advantage of using the <code>PreparedStatement</code> is a more versatile query, treating the stored procedure as a table, on which I can use <code>WHERE</code>, <code>JOIN</code>, <code>ORDER BY</code>, etc.</p>
  
  <p>Are there aspects or differences between the methods that I'm missing? In the case of a stored procedure used as a query, which is recommended?</p>