Guest User

Untitled

a guest
Nov 4th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. package br.fiap.conexao;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6.  
  7. import javax.swing.JOptionPane;
  8.  
  9. public class Conexao {
  10. private static Connection connection;
  11. private static final String DRIVER = "oracle.jdbc.driver.OracleDriver";
  12. private static final String URL = "jdbc:oracle:thin:@oracle.fiap.com.br:1521:ORCL";
  13. private static final String USUARIO = "";
  14. private static final String SENHA = "";
  15.  
  16. private Conexao() {}
  17.  
  18. public static synchronized Connection getConnection() {
  19. if(connection == null) {
  20. try {
  21. Class.forName(DRIVER);
  22. connection = DriverManager.getConnection(URL, USUARIO, SENHA);
  23. }
  24. catch(ClassNotFoundException e) {
  25. JOptionPane.showMessageDialog(null, "Erro ao carregar o driver de conexão\n"+e);
  26. }
  27. catch(SQLException e) {
  28. JOptionPane.showMessageDialog(null, "Erro ao estabelecer conexão com o banco de dados\n"+e);
  29. }
  30. }
  31. return connection;
  32. }
  33. }
Add Comment
Please, Sign In to add comment