package librerias; import java.sql.*; public class mantenimiento{ private String mydriver; private String myurl; private String myuser; private String mypwd; private java.sql.Connection myconeccion = null; public mantenimiento() { super(); } public void CerrarConeccion() throws SQLException{ this.getMyconeccion().close(); } public String Conectarme() { String rpta="OK"; java.sql.Connection con; if (this.getMyconeccion()==null){ try { Class.forName(this.getMydriver()).newInstance(); con = DriverManager.getConnection(this.getMyurl(),this.getMyuser(), this.getMypwd()); this.setMyconeccion(con); }catch (Exception e){ rpta = "ERROR: " + e.getMessage(); this.setMyconeccion(null); } } return rpta; } public String ConectarmePool() { String rpta="OK"; java.sql.Connection con; if (this.getMyconeccion()==null){ try { Context ctx = (Context) new InitialContext().lookup("java:comp/env"); //con = ((DataSource) ctx.lookup("jdbc/pgventas")).getConnection(); con = ((DataSource) ctx.lookup(this.getMyurl())).getConnection(); this.setMyconeccion(con); } catch (Exception e){ rpta = "ERROR: " + e.getMessage(); this.setMyconeccion(null); } } return rpta; } protected void finalize () throws Throwable { try{ if (this.getMyconeccion().isClosed()==false || this.getMyconeccion() != null ){ this.CerrarConeccion(); } } catch (Exception e){ this.CerrarConeccion(); } finally { super.finalize(); } } public java.sql.Connection getMyconeccion() { return this.myconeccion; } public void setMyconeccion(java.sql.Connection myconeccion) { this.myconeccion = myconeccion; } public String getMydriver() { return this.mydriver; } public void setMydriver(String mydriver) { this.mydriver = mydriver; } public String getMyurl() { return this.myurl; } public void setMyurl(String myurl) { this.myurl = myurl; } public String getMyuser() { return this.myuser; } public void setMyuser(String myuser) { this.myuser = myuser; } public String getMypwd() { return this.mypwd; } public void setMypwd(String mypwd) { this.mypwd = mypwd; } public String getMyfileconfiguration() { return this.myfileconfiguration; } public void setMyfileconfiguration(String myfileconfiguration) { this.myfileconfiguration = myfileconfiguration; } }