|
INTERVIEW QUESTIONS
J2EE
JDBC
DETAILS
Question: How do you implement Connection Pooling?
Answer: Connection pooling is performed in the background and does not affect how an application is coded; however, the application must use a DataSource object (an object implementing the DataSource interface) to obtain a connection instead of using the DriverManager class. A class implementing the DataSource interface may or may not provide connection pooling. A DataSource object registers with a JNDI naming service. Once a DataSource object is registered, the application retrieves it from the JNDI naming service in the standard way. For example:
Context ctx = new InitialContext(); DataSource ds = (DataSource) ctx.lookup("jdbc/SequeLink");
If the DataSource object provides connection pooling, the lookup returns a connection from the pool if one is available. If the DataSource object does not provide connection pooling or if there are no available connections in the pool, the lookup creates a new connection. The application benefits from connection reuse without requiring any code changes. Reused connections from the pool behave the same way as newly created physical connections. The application makes a connection to the database and data access works in the usual way. When the application has finished its work with the connection, the application explicitly closes the connection. For example:
Connection con = ds.getConnection("scott", "tiger"); // Do some database activities using the connection... con.close();
The closing event on a pooled connection signals the pooling module to place the connection back in the connection pool for future reuse.
Submitted by Sateesh Velaga ([email protected])
|
|
|
Category |
JDBC Interview Questions & Answers -
Exam Mode /
Learning Mode
|
Rating |
(0.3) By 8781 users |
Added on |
1/27/2011 |
Views |
78792 |
Rate it! |
|
|
Question:
How do you implement Connection Pooling?
Answer:
Connection pooling is performed in the background and does not affect how an application is coded; however, the application must use a DataSource object (an object implementing the DataSource interface) to obtain a connection instead of using the DriverManager class. A class implementing the DataSource interface may or may not provide connection pooling. A DataSource object registers with a JNDI naming service. Once a DataSource object is registered, the application retrieves it from the JNDI naming service in the standard way. For example:
Context ctx = new InitialContext(); DataSource ds = (DataSource) ctx.lookup("jdbc/SequeLink");
If the DataSource object provides connection pooling, the lookup returns a connection from the pool if one is available. If the DataSource object does not provide connection pooling or if there are no available connections in the pool, the lookup creates a new connection. The application benefits from connection reuse without requiring any code changes. Reused connections from the pool behave the same way as newly created physical connections. The application makes a connection to the database and data access works in the usual way. When the application has finished its work with the connection, the application explicitly closes the connection. For example:
Connection con = ds.getConnection("scott", "tiger"); // Do some database activities using the connection... con.close();
The closing event on a pooled connection signals the pooling module to place the connection back in the connection pool for future reuse.
Submitted by Sateesh Velaga ([email protected]) Source: CoolInterview.com
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|
Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.
View All JDBC Interview Questions & Answers - Exam Mode /
Learning Mode
|