Instrucciones para la definicin de un Datasource en Tomcat 6 Mdulo4
4. In the program code use the following to obtain a connection public static Connection getConexion() { Connection con = null; try { /* * The InitialContext is made available to web application * components (for read-only access). */ Context ctx = new InitialContext(); /* * Look up the datasource from the starting portion of the JNDI * namespace being served up by tomcat. All configured entries * and resources are placed in the java:comp/env portion of the * JNDI namespace. When accessing the datasource programmatically, * remember to prepend java:/comp/env to your JNDI lookup */ DataSource ds = (DataSource)ctx.lookup("java:/comp/env/jdbc/bibliotecads"); /* * finally get the connection object */ con = ds.getConnection(); System.out.println("conexion "+con+" obtenido desde el pool: "+ds); } catch (Exception e) { throw new RuntimeException( "\nNo se puede conectar dado que datasource=jdbc/bibliotecads+ "\n" + e.getMessage() ); } return con; } public static void cerrar(Connection conn) throws SQLException{ if (conn != null) { conn.close(); System.out.println("conexion devuelta al pool"); } }