You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
SIPRP/trunk/PlanosActuacao/src/java/db/DbRelatorios.java

75 lines
2.5 KiB

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