简体   繁体   English

连接池,jdbc和jndi的差异

[英]Differences of connection pool, jdbc and jndi

I need to know if my understanding on the above is correct. 我需要知道我对上述内容的理解是否正确。

In a connection pool you set multiple connections with the use of java.sql.Datasource. 在连接池中,使用java.sql.Datasource设置多个连接。

In jdbc we directly specify the connection url and oracle.jdbc.driver.OracleDriver and it's always one connection, where another request has to wait until the connection has finished processing. 在jdbc中,我们直接指定连接url和oracle.jdbc.driver.OracleDriver,它始终是一个连接,其中另一个请求必须等到连接完成处理。

And with JNDI it's similar to direct jdbc where we refer the jdbc setting via a name, so that we can specify the connection url and other setting in the application server and not have them bound to the application, right? 使用JNDI,它类似于直接jdbc,我们通过名称引用jdbc设置,以便我们可以在应用程序服务器中指定连接URL和其他设置,而不是将它们绑定到应用程序,对吧?

Well these are two different things. 这些是两件不同的事情。

JDBC is Java Database Connectivity API, while JNDI is Java Naming and Directory Interface API. JDBC是Java数据库连接API,而JNDI是Java命名和目录接口API。

The main thing here is that in a JNDI directory you're actually storing a JDBC DataSource, so, you're simply using JDBC to obtain a Connection via JNDI lookup. 这里的主要内容是,在JNDI目录中,您实际上存储的是JDBC DataSource,因此,您只需使用JDBC通过JNDI查找来获取Connection。

In short words: JDBC is Database realm, JNDI lets you store Objects in a virtual context (the Directory) that can be local, remote (implementation details usually don't matters). 简而言之:JDBC是数据库领域,JNDI允许您将对象存储在虚拟上下文(目录)中,可以是本地的,远程的(实现细节通常无关紧要)。

You access this context via names, obtaining stored objects, is good to share things among different modules. 您可以通过名称访问此上下文,获取存储的对象,最好在不同模块之间共享内容。

Application Servers usually have a JNDI Context for sharing global objects among different application, Connection Poolers happen to be one of the most clear example of why sharing via JNDI is good (define 1 connection pooler, share between several webapps). 应用服务器通常有一个JNDI上下文用于在不同的应用程序之间共享全局对象,连接Poolers恰好是为什么通过JNDI共享的最明显的例子之一(定义1个连接池,在几个webapps之间共享)。

I know all the acronyms are daunting when you first learned Java, but get used to it, spend a lot of time reading .. especially official resources from Java/Oracle 我知道你第一次学习Java时所有的缩略词都是令人生畏的,但是要习惯它,花很多时间阅读...特别是来自Java / Oracle的官方资源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM