Ver Mensaje Individual
  #3 (permalink)  
Antiguo 07/10/2004, 15:54
milsoncardona
 
Fecha de Ingreso: septiembre-2003
Mensajes: 47
Antigüedad: 20 años, 8 meses
Puntos: 0
gracias por el interes amigo Hugo

//en este servlet intento acceder al contexto para recuperar el pool y luego obtener la conexion

public class DAOUtil extends HttpServlet {
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
public Connection getConexion(){
Connection conexion = null;
try{
ConnectionPool pool = (ConnectionPool) getServletContext().getAttribute("CONNECTION_POOL" );
if (pool == null){
throw new UnavailableException("no pudo capturar la conexion ");
}
conexion = pool.getConnection();
}catch(Exception e){
throw e;
}finally{
return conexion;
}
}
}

--------------------------------------------------------------------------
//asi creo el POOL DE CONEXIONES y lo subo al contexto

public class ConnectionPoolServlet extends HttpServlet {

//Initialize global variables
public void init(ServletConfig config) throws ServletException {
super.init(config);
ConnectionPool pool = new ConnectionPool();
try {
pool.setDriver("oracle.jdbc.driver.OracleDriver");
pool.setURL("jdbc:oracle:thin:@xxxxx");
pool.setSize(4);
pool.setUsername("nnnn");
pool.setPassword("nnnnn");

// Initialize the pool
pool.initializePool();

ServletContext context = getServletContext();
context.setAttribute("CONNECTION_POOL", pool);
}catch (Exception e) {
System.err.println(e.getMessage());
}
}

}

--------------------------------------------------------------------------

espero que me puedas ayudar con este problema..