Question: So I need to do a query based on the results of another query.   
Is there a way for me to set the result of a query to a variable so I can use the result of that in another query?

Example:  

{original query} --->

```
SELECT
tablea.number

FROM tablea

INNER JOIN tableb

ON tablea.name = tableb.name

WHERE tableb.zip = '11111'

```

Now I want to use this result to then do another query:

```
SELECT *

FROM tablea

WHERE number = (results of last query)

```

I think theres a way to set the first query to a variable so that that way the second one can just use the result, just not sure how. Thanks.

Answer: 
`System.exit` if successful does not return even via throwing an exception, so the thread will never complete. This wasn't an issue before shutdown hooks.

Workaround would be to usual standard locks (or even just hack it with `new Thread(new Runnable() { public void run() { System.exit(0); }}).start();`).
What you are doing is [specifically prohibited](http://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html#addShutdownHook%28java.lang.Thread%29):

> 
> Shutdown hooks should also finish their work quickly.
> 
> 
> 

Joining random threads cannot be described as 'quick'.

Obviously those threads should close their *own* streams when they exit. If they don't exit, how will calling `join()` accomplish anything?