Both are database connections. A connection is a handle to database. When you are directly creating a connection by calling Drivermanager.getConnection(..) , you are creating a connection by yourself and when closing close() on it, the link to database is lost. On the other hand when you get a connection from a datasource, when you call the close() on it, it will not close the link to database, but will return to a connection pool where it can be reused by some other classes. It is always better to use a connection pool because creating connections are expensive
DriverManager.getConnection() literally creates, that is, builds a connection to the database using the values you previously supplied when you loaded the driver.
A connection pool is an object that contains several already made connections to the database, and simply provides you with one of those existing connections. The confusion arises because a) the method name is frequently the same and b) the connection pool object calls the driver's getConnection() method to create several connections before lending any of them out.
In other words:
DriverManager.getConnection() builds a connection to the database.
ConnectionPool.getConnection() fetches an existing connection.
If you use DriverManager.getConnection(), you are indeed bypassing the Connection Pool entirely.
Subscribe to:
Post Comments (Atom)
Topics
- ActionScript (1)
- Ajax (1)
- Apache mod_SSL (1)
- Apache SSL (2)
- Backup a Certificate (1)
- CA (1)
- connection pooling (1)
- cryptography (1)
- CSR (1)
- CSR Generation Instructions- Tomcat (1)
- Database Connection Pooling with Tomcat (1)
- datasource connection (1)
- Difference between equals and hashCode method (1)
- Difference between JDBC and hibernate (1)
- Difference between String StringBuffer and StringBuilder (1)
- Different types of SQL Joins (1)
- digital certificate (1)
- Digital Certificate Enrollment (1)
- digital certificate installation (1)
- DOM (2)
- DTD (1)
- encryption (1)
- Events in Flex (1)
- Flex Data Access (1)
- generate certificate (1)
- Good Java Interview questions (1)
- Hibernate (1)
- Hibernate Interview questions (1)
- Hibernate Interview questions 1 (1)
- Hibernate Interview questions 2 (1)
- Hibernate Interview questions 3 (1)
- Hibernate Vs. iBatis? (1)
- https (2)
- Import Certificate (1)
- Java Web development interview questions (1)
- JavaInterviewQuestions (1)
- JavaScriptAJAXinterview (1)
- jdbc connection (1)
- JDBC Questions 1 (1)
- JDBC Questions 2 (1)
- JSP interview questions (1)
- Junit (5)
- links (1)
- Move a Certificate (1)
- Multithreading (1)
- MXML (1)
- private key (1)
- public key (1)
- Running multiple Tomcat instances on one server (1)
- SAX (1)
- SCHEMA (1)
- Secure Socket Layer (1)
- Servlet Questions 1 (1)
- Servlet Questions 2 (1)
- Servlet Questions 3 (1)
- ShellScriptingquestions (1)
- Simple Java Questions (1)
- Singleton Design Pattern (1)
- siteminder sso netegrity (1)
- SSL (3)
- StringBuffer versus String (1)
- Third Normal Form (1)
- Unix (1)
- What is connection pooling? (1)
- What's the difference between "PreparedStatement" and "Statement"? (1)
- What's the differences between object and object references? (1)
- XML (1)
- XML Questions 1 (1)
- XML Questions 2 (1)
No comments:
Post a Comment