Presentation is loading. Please wait.

Presentation is loading. Please wait.

JDBC Data source and Connection pooling 1 JDBC Data sources and Connection pooling.

Similar presentations


Presentation on theme: "JDBC Data source and Connection pooling 1 JDBC Data sources and Connection pooling."— Presentation transcript:

1 JDBC Data source and Connection pooling 1 JDBC Data sources and Connection pooling

2 JDBC Data source and Connection pooling 2 Getting a connection, 33 "Old" way of getting a connection –DriverManager.getConnection(url, user, pw); "New" way of getting a connection –DataSource ds = … –ds.getConnection(); Data source has URL, username, password –interface javax.sql.DataSourceJDK 1.4 –Example DataSourceExample.java

3 JDBC Data source and Connection pooling 3 Different connections, 34 A data source object may produce 3 kinds of connections –basic connections –pooled connections more on that little later –connections for distributed connections no more on that subject now!

4 JDBC Data source and Connection pooling 4 Long or short lived connections? Problems –It takes a relatively long time to open / close a connection Naive solution: Keep the connection open "forever" –A DBMS can have N open connections Naive solutions: Close connections as soon as possible –Naive solutions are conflicting –Combined solution Connection pool!

5 JDBC Data source and Connection pooling 5 Connection pool, 38 Ideas –The application (server) allocates a pool of connections to the database (e.g. 10 connections) –Applications programmers don't create connections, but borrows a connection the from the pool. Advantages –Connections are "recycled" –Few physical connections Implemented by driver –Old days: implemented by application programmer Example PooledConnection1.java

6 JDBC Data source and Connection pooling 6 JDBC vs. Oracle API JDBC, javax.sql –DataSource produces Connection –ConnectionPoolDataSource produces PooledConnection Oracle, oracle.jdbc.pool –OracleDataSource produces Connection –OracleConnectionPoolDataSource produces PooledConnection –Oracle factories produces "Sun objects".

7 JDBC Data source and Connection pooling 7 Data source and connection pool Mainly used with servers –J2EE / EJB application server –Web-server (e.g. Apache Tomcat) Data source object –deployed with the server –used by application programmers Usage in Servlets / JSP –deploy with Apache Tomcat –doGet(…) acquire connection from pool query database "close" connection (back to pool)


Download ppt "JDBC Data source and Connection pooling 1 JDBC Data sources and Connection pooling."

Similar presentations


Ads by Google