OracleConnection Lifespan - Best Practices

I use the standard Oracle driver to connect to the database, but I cannot agree with my colleagues throughout the life of OracleConnection. It is expensive? Is it thread safe? Can I reuse it between requests or should I create a new one for each request?

I would appreciate a more detailed explanation of which method of use is preferred and why.

+4
source share
2 answers

Please correct me if I am wrong, but it seems that by default the oracle driver automatically connects database connections. Therefore, it is best to create a new OracleConnection object before each request and delete it after - it will be taken from the connection pool if it is available or otherwise created.

+4
source

It is expensive (i.e. it takes a long time, such as 1-2 seconds) to create, so you should use a connection pool. This is a very common problem that has already been solved.

+1
source

All Articles