/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package db; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import com.evolute.utils.error.ErrorLogger; /** * * @author lluis */ public class DblocalRelatorios { // String connectionURL = "jdbc:postgresql://evoserver/siprp_local_3_20100713"; //testes local_3 String connectionURL = "jdbc:postgresql://localhost:5436/siprp_local_3"; String User = "postgres"; String Pass = null; Connection connection = null; public Connection connect() throws Exception { Class.forName("org.postgresql.Driver").newInstance(); connection = DriverManager.getConnection(connectionURL, User, Pass); //HttpSession session = (HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(true); //session.setAttribute("connection_local", connection); return connection; } public Statement createStatement() { //HttpSession session = (HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(false); //connection = (Connection) session.getAttribute("connection_local"); Statement st; try { st = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); return st; } catch(Exception ex) { ErrorLogger.logException( ex ); return null; } } public void close() throws Exception { connection.close(); } }