previous | start | next

## A Three-Tier Application

- To obtain a database connection, first look up the data source that was configured in the JSF container:

      InitialContext ctx = new InitialContext();
      DataSource source = (DataSource) ctx.lookup("java:comp/env/jdbc/mydb");
      Connection conn = source.getConnection();
      try
      {
         Use the connection
      }
      finally
      {
         conn.close();
      }

- JSF containers such as Tomcat manage a pool of database connections
  - Pooling avoids the overhead of creating new database connections
  - Pooling is completely automatic

previous | start | next