Guest User

Untitled

a guest
Nov 7th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.SQLException;
  4. import java.util.logging.Level;
  5. import java.util.logging.Logger;
  6.  
  7. public class Conexion {
  8. public static Conexion instancia; //singleton
  9. private static final String DRIVER = "oracle.jdbc.driver.OracleDriver";//modificar
  10. private static final String USER = "USUARIOBD";//modificar
  11. private static final String PASSWORD = "PASSWORDBD";//modificar
  12. private static final String DATABASE = "DATABASE";//modificar
  13. private static final String DSN = "jdbc:oracle:thin:@localhost:1521:" + DATABASE;
  14. private Connection conexion;
  15.  
  16. public Conexion() {
  17. super();
  18.  
  19. try {
  20. Class.forName(DRIVER);
  21. conexion = DriverManager.getConnection(DSN, USER, PASSWORD);
  22. } catch (ClassNotFoundException error) {
  23. Logger.getLogger(Conexion.class.getName()).log(Level.SEVERE, null, error);
  24. } catch (SQLException error) {
  25. Logger.getLogger(Conexion.class.getName()).log(Level.SEVERE, null, error);
  26. }
  27. }
  28.  
  29. //Singleton
  30. public synchronized static Conexion saberEstado()
  31. {
  32. if (instancia == null) {
  33. instancia = new Conexion();
  34. }
  35.  
  36. return instancia;
  37. }
  38.  
  39. public void cerrarConexion()
  40. {
  41. instancia = null;
  42. }
  43.  
  44. public Connection getConexion() {
  45. return conexion;
  46. }
  47. }
Add Comment
Please, Sign In to add comment