Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This exception is typical when a single connection is shared between multiple threads. This will in turn happen when your code does <em>not</em> follow the standard JDBC idiom of acquiring and closing the DB resources in the shortest possible scope in the very same <code>try-finally</code> block like so:</p> <pre><code>public Entity find(Long id) throws SQLException { Connection connection = null; // ... try { connection = dataSource.getConnection(); // ... } finally { // ... if (connection != null) try { connection.close(); } catch (SQLException ignore) {} } return entity; } </code></pre> <p>Your comment on the question,</p> <blockquote> <p><em>@TejasArjun i used connection pooling with servlet Init() method.</em></p> </blockquote> <p>doesn't give me the impression that you're doing it the right way. This suggests that you're obtaining a DB connection in servlet's <code>init()</code> method and reusing the same one across all HTTP requests in all HTTP sessions. This is absolutely not right. A servlet instance is created/initialized only once during webapp's startup and reused throughout the entire remaining of the application's lifetime. This at least confirms the exception you're facing.</p> <p>Just rewrite your JDBC code according the standard <code>try-finally</code> idiom as demonstrated above and you should be all set. </p> <h3>See also:</h3> <ul> <li><a href="https://stackoverflow.com/questions/9428573/is-it-safe-to-use-a-static-java-sql-connection-instance-in-a-multithreaded-syste/9431863#9431863">Is it safe to use a static java.sql.Connection instance in a multithreaded system?</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload