Few questions on JDBC coding:
- For a single client application, do we need a Connection pool?
- Is it a good idea to create a
Connectionat the beginning and keep it alive without close it until application exit? Why? PreparedStatementis associated withConnection, if my connection is not closed after each query, why not keep thePreparedStatementalive and reuse it in other methods?- if we create
PreparedStatementeach query, does the database knows it is the samePreparedStatementand ignore unnecessary actions after the first time? PreparedStatementis not create once and reuse many times statement? If yes, why need to close it each time?
I know the call to close() will release the resource. But If we know we are going to use it later, why release it and then request it again later?
How about a multi-client application? We need a connection pool and so we need to create and close Connection, Statement, and PreparedStatement each time?