title: Retrieving SQL query execution results asynchronously.
body: <p>After quite a bit of research I decided to go ahead and write a question that may seem fairly redundant here on stack-overflow, but I'm only asking because I've failed to find my answer. I've been having some fun with the Java NIO2 framework which has increased the scalability of my applications tremendously. (We were previously using the old-school I/O TPC server/client setup for some mildly populated emulation servers), and let me tell you. Concurrency was queen B if you know what I mean.</p>
  
  <p>We're moving from using threads as an answer to everything (In an attempt to better practices and become more familiar with advancing technology). Previously we were using flat-file storage (Text/Binary format storage) for user-data and have migrated everything over to a SQL database. </p>
  
  <p>While doing this I've noticed that there's usually not a problem, however waiting on the database is never fun, and in an emulated game-environment waiting for a database call is never fun, especially when the entire game-server is waiting. This is where we would usually substitute threading. Why not just execute the SQL call on another thread using a <code>Thread pool</code> or similar. </p>
  
  <p>The Java NIO2 <code>CompletableFuture&lt;K,V&gt;</code> has really been a huge help with any type of asynchronous event, however I've been trying to find a way to use this with SQL calls. I figured writing our own version of JDBC that used NIO2 was always an option but it seems a bit over-kill and will probably take more time and money than it's worth. Remember we're just a small emulation community, not a large-scale business, but we do want to make sure to provide quality to our users. </p>
  
  <p>I was looking into <code>jooQ</code> which seems alright, but it also seems a little over-kill. This uses the <code>CompletableFuture#supplyAsych</code> method however the example available don't really explain it in-depth. However it's mixed in with this quote:</p>
  
  <blockquote>
    <p>there will always be one blocking barrier to such solutions, and that
    is JDBC itself – which is very hard to turn into an asynchronous API.
    In fact, few databases really support asynchronous query executions.</p>
  </blockquote>
  
  <p>However, the database doesn't necessarily need to support asynchronous query executions in-order for the results to be provided in an asynchronous context. If my server isn't waiting(and only waiting) for the API to get results for the query, that's the only thing that really matters here. Similar activity to this can be explained by using an example from Unity's scripting reference: <a href="http://docs.unity3d.com/Manual/Coroutines.html" rel="nofollow">CoRoutines</a>.</p>
  
  <p>Please do not recommend Scala. </p>