/* * 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 { //production private String server = "localhost"; private int port = 5436; private String db_name = "siprp_local_3"; private String User = "postgres"; private String Pass = null; //tests // private String server = "evoserver"; // private int port = 5432; // private String db_name = "siprp_local_3_20100813"; // private String User = "postgres"; // private String Pass = null; private String connectionURL = "jdbc:postgresql://" + server + ":" + port + "/" + db_name; // String connectionURL = "jdbc:postgresql://evoserver/siprp_local_3_20100813"; //testes local_3 // String connectionURL = "jdbc:postgresql://localhost:5436/siprp_local_3"; private 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(); } }