Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- public class Conexion {
- public static Conexion instancia; //singleton
- private static final String DRIVER = "oracle.jdbc.driver.OracleDriver";//modificar
- private static final String USER = "USUARIOBD";//modificar
- private static final String PASSWORD = "PASSWORDBD";//modificar
- private static final String DATABASE = "DATABASE";//modificar
- private static final String DSN = "jdbc:oracle:thin:@localhost:1521:" + DATABASE;
- private Connection conexion;
- public Conexion() {
- super();
- try {
- Class.forName(DRIVER);
- conexion = DriverManager.getConnection(DSN, USER, PASSWORD);
- } catch (ClassNotFoundException error) {
- Logger.getLogger(Conexion.class.getName()).log(Level.SEVERE, null, error);
- } catch (SQLException error) {
- Logger.getLogger(Conexion.class.getName()).log(Level.SEVERE, null, error);
- }
- }
- //Singleton
- public synchronized static Conexion saberEstado()
- {
- if (instancia == null) {
- instancia = new Conexion();
- }
- return instancia;
- }
- public void cerrarConexion()
- {
- instancia = null;
- }
- public Connection getConexion() {
- return conexion;
- }
- }
Add Comment
Please, Sign In to add comment