Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differences of connection pool, jdbc and jndi

Tags:

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.

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.

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?

like image 350
Harshana Avatar asked Mar 28 '13 08:03

Harshana


People also ask

What is a JNDI connection?

The Java Naming and Directory Interface (JNDI) is a Java API for a directory service that allows Java software clients to discover and look up data and resources (in the form of Java objects) via a name.

What is JDBC connection pool?

A JDBC connection pool is a group of reusable connections for a particular database. Because creating each new physical connection is time consuming, the server maintains a pool of available connections to increase performance. When an application requests a connection, it obtains one from the pool.

Does JDBC use connection pooling?

The JDBC 3.0 API provides a general framework with "hooks" to support connection pooling rather than specifying a particular connection pooling implementation.

Why JNDI is used in Java?

The Java Naming and Directory Interface (JNDI) provides consistent use of naming and/or directory services as a Java API. This interface can be used for binding objects, looking up or querying objects, as well as detecting changes on the same objects.


1 Answers

Well these are two different things.

JDBC is Java Database Connectivity API, while JNDI is Java Naming and Directory Interface 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.

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).

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).

like image 180
BigMike Avatar answered Sep 27 '22 21:09

BigMike