Monday, April 6, 2009

Connection pool/jndi

In normal java development, we use jdbc database connections. It takes several mili seconds to make connection between database server and your application.

In connection pool concept, there are several connections are built with the application server startup. This make web applications more fast.

As i mentioned, it makes several connection at the app sever startup. Developers can access those connections using jndi. There is a jndi for a conncetion pool. All the jndi are in the java jvm.

Developers has to look up for the jndi names and use the database connection.

Suppose your connection pool is "dbtest" . And you have mapped this pool with jndi name "jdbc/dbtest".

your lookup mathod will be like this in netbeans.

private DataSource getDbtest() throws NamingException {
Context c = new InitialContext();
return (DataSource) c.lookup("java:comp/env/dbtest");

The above method returns a sql data source. You can get a connection using it.

No comments:

Post a Comment