为OracleConnection一生 - 最佳实践 [英] OracleConnection lifetime - best practises

查看:118
本文介绍了为OracleConnection一生 - 最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是标准的Oracle驱动程序连接到数据库中,但我真的不能与我的同事为OracleConnection的寿命同意。它是昂贵的创造?难道是线程安全的?我可以重复使用它的要求之间,或者我应该创建一个新的为每个请求?

I am using the standard Oracle driver to connect to the database, but I can't really agree with my colleagues on the lifespan of OracleConnection. Is it expensive to create? Is it thread safe? Can I reuse it between request, or should I create a new one for every request?

我将不胜感激了一下更详细的解释其使用的方式,它是preferred以及为什么。

I would be grateful for a bit more detailed explanation which way of using it is preferred and why.

推荐答案

请纠正我,如果我错了,但它在默认情况下,Oracle驱动程序池连接到数据库自动看来。因此,这里的最佳做法似乎每个请求之前创建一个新的OracleConnection对象,后处理它 - 它将被从连接池(如果可用),或以其他方式创建

Please correct me if I am wrong, but it seems that by default the oracle driver pools connections to the database automatically. So the best practise here seems to create a new OracleConnection object before every request and dispose it after - it will be taken from the connection pool if available or created otherwise.

这篇关于为OracleConnection一生 - 最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆