forked from Coded/SIPRP
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.
73 lines
1.9 KiB
73 lines
1.9 KiB
/*
|
|
* Dblocal.java
|
|
*
|
|
* Created on September 20, 2007, 2:07 PM
|
|
*
|
|
* To change this template, choose Tools | Template Manager
|
|
* 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;
|
|
import javax.faces.context.FacesContext;
|
|
import javax.servlet.http.HttpSession;
|
|
|
|
/**
|
|
*
|
|
* @author lluis
|
|
*/
|
|
public class Dblocal
|
|
{
|
|
// String connectionURL = "jdbc:postgresql://evoserver:5432/siprp_local_3_20100713"; //testes
|
|
String connectionURL = "jdbc:postgresql://localhost:5436/siprp_local_3";
|
|
|
|
String User = "postgres";
|
|
String Pass = null;
|
|
|
|
|
|
Connection connection = null;
|
|
|
|
/** Creates a new instance of Dblocal */
|
|
public Dblocal()
|
|
{
|
|
}
|
|
|
|
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();
|
|
}
|
|
|
|
}
|