Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A much better way of doing this is using a connection pool. You also need to ensure that you close the connections properly (is isn't clear from your code if this is happening, with a pool it still needs to be done). As for storing the connection, that is not really a good idea as your servlet is multithreaded (I learned this the hard way) and you would need to sychronize all accesses which would be a bit of a disaster . </p> <p><a href="http://geekexplains.blogspot.co.uk/2008/06/what-is-connection-pooling-why-do-we.html" rel="nofollow">http://geekexplains.blogspot.co.uk/2008/06/what-is-connection-pooling-why-do-we.html</a></p> <p><a href="http://confluence.atlassian.com/display/DOC/Configuring+a+PostgreSQL+Datasource+in+Apache+Tomcat" rel="nofollow">http://confluence.atlassian.com/display/DOC/Configuring+a+PostgreSQL+Datasource+in+Apache+Tomcat</a></p> <p><a href="http://www.devdaily.com/blog/post/java/how-configure-tomcat-dbcp-connection-pool-pooling-postgres" rel="nofollow">http://www.devdaily.com/blog/post/java/how-configure-tomcat-dbcp-connection-pool-pooling-postgres</a></p> <p>--EDIT-- Why not do it in "init()"?</p> <p>Learn about the "life cycle of a servlet". </p> <p>init() is only called once when the servlet is set up by the container.</p> <p>Each request is using the same servlet not a new instance for each request. So init() will not be called for a request.</p> <p>As each request is processed by the same servlet instance, your code needs to be multithreaded.</p>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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