Advertisement
Guest User

Untitled

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