What is faster: JDBC or JNDI?

database, java, jdbc, jndi, mysql

Solution

I bet what you mean is choosing from

- creating datasource or jdbc connection manually in your application, or

- setup the datasource in the container, and application lookup the datasource through JNDI

If it is the case, always stick to 2 if possible.

The main reasons for the choice is never the performance differences. The reason for sticking to 2 is in most cases is, you need 2 to gain more advanced features from container, for example, distributed transaction.

Problem

I have two options to configure my application database connection - one is using JDBC, another one is using JNDI. What will be the best option in terms of how fast those connection types work with the database. I understand those are two different types of database connections using different principles (JDBC is a direct db connection, JNDI is a database connection pool configuration on application server side). But are there other general JDBC/JNDI pros and cons which might be more important than operating speed? If yes, what are they?

Original source