Code below shows how to use connection cache from JSP:

Note: myconnection contains the cache name to be used

Java Code:
javax.naming.InitialContext ctx = new javax.naming.InitialContext();
  javax.sql.DataSource ds = (javax.sql.DataSource)
      ctx.lookup("java:comp/env/jdbc/myconnection");
  java.sql.Connection con = ds.getConnection();
  java.sql.PreparedStatement stmt = con.prepareStatement(sql);
  java.sql.ResultSet rs = stmt.executeQuery();

  while (rs.next()) {
     //do something
  }