java - When to close Connection, Statement, PreparedStatement and ResultSet in JDBC -


Some questions on JDBC coding:

  1. For a client application, do we have a connection Pool?
  2. Is it a good idea to make connections at the beginning and exit it without closing it? Why?
  3. The location created is connected with the connection, if my connection is not closed after every query, why not keep the preparedness alive and do not reuse it in other methods. Do you?
  4. If we do every query, does the database know that it was created the same and could ignore unnecessary actions for the first time?
  5. Once created, the statement is not made once and many times the statement is not being reused? If so, why should it be shut down every time?

I know that the call to stop () will release the resource, but if we know that we are going to use it later, why release it and then later Request again?

How about the multi-client application? We need a connection pool and why do we need to create and close the statements, statements and statements made every time?

Thanks,

Personally I use a pool because it You will take care of all resource management. If your connection requirements change then you can easily modify the pool configuration. With a pool you can open / close resource management for pools and build connections and prepare resources.

Usually, when using a pool:

  • A connection will actually return to the pool
  • The task of creating a statement is either connection Will retake the statements made before the cash, or if no one is available, then create a new statement and cache it for later use.
  • The closure of a prepared statement will actually return only to the statement of the connection. Apart from this - depending on the pool implementation - it may be possible to let you know these problems in your code when the resource leaks are able to notify you.

    Take a look at the example of the example implementation - like how they work, it is very interesting.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -