title: Jdbc connection close and preparedstatement close
body: <p>Hi all I knew it is a old question but just curious today. As we know connection.close will also close preparedStatement(correct me if I am wrong). but what if I close connection then close preparedStatement </p>
  
  <pre><code>conn.close();
  ps.close();
  </code></pre>
  
  <p>Will I get a nullpointer exception? </p>
  
  <p>Someone was saying depends on your jvm speed.sometimes ps.close() will run ahead and close first before conn.close finish his job and so you wont get nullpointer.</p>
  
  <p>In order to test that, I have modified the code</p>
  
  <pre><code>conn.close();
  Thread.sleep(5000);//I give 5s to conn.close to finish his work. should be enough
  ps.close();
  </code></pre>
  
  <p>But I didn't get the nullpointer.</p>
  
  <p>So my question is what happened here if i close conn first and then ps.</p>
  
  <p>thanks all.</p>