java - create connection pool from a class -


to connect database performed: 1.-create class conexionx place data connection (no connection pool) 2.-in dao class connection conexionx class, in order manipulate database.

my question how can connection pool?

i tried following, not work

poolconexiones.java

not servlet normal class

package modelo;  import java.sql.*; import javax.sql.*; import javax.servlet.*; import javax.servlet.http.*; import javax.naming.*;  /*  * change template, choose tools | templates  * , open template in editor.  */  public class poolconexiones extends httpservlet {      private  datasource sourcedb = null;     private  connection con=null;     @override     public void init(servletconfig config) throws servletexception {         // todo auto-generated method stub         super.init(config);          try {             // recuperamos el contexto inicial y la referencia la fuente de             // datos             context ctx = new initialcontext();             sourcedb = (datasource) ctx.lookup("java:comp/env/jdbc/practica5");         } catch (exception e) {             throw new servletexception(                     "imposible recuperar java:comp/env/jdbc/tutoriales", e);         }     }      public  connection getconnection() {          try {             synchronized (sourcedb) {                 con=sourcedb.getconnection();             }             if(con==null){                   throw new servletexception("problemas con la conexion");             }         } catch (sqlexception e) {             e.printstacktrace();         } catch (servletexception e) {       // todo auto-generated catch block         e.printstacktrace();     }     return con; } public void cerraconexion(){      try {         con.close();     } catch (sqlexception e) {         // todo auto-generated catch block         e.printstacktrace();     } } 

}


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -