SHARE
TWEET

Untitled

a guest Jul 21st, 2017 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Conectar
  2. public String conectarDB() {
  3.  
  4.     // Variáveis
  5.     String driver = "org.postgresql.Driver";
  6.     String dbURL = "jdbc:postgresql://localhost:5432/database";
  7.     String user = "postgres";
  8.     String pass = "123456";
  9.  
  10.     try{
  11.  
  12.         //Carrega o driver
  13.         Class.forName(driver);
  14.         Connection conn = DriverManager.getConnection(dbURL, user, pass);
  15.         return "Conexão: Ok!";
  16.  
  17.     } catch(ClassNotFoundException e) {
  18.         e.printStackTrace();
  19.         return "Conexão: Erro Driver!";
  20.  
  21.     } catch (SQLException e) {
  22.         e.printStackTrace();
  23.         return "Conexão: Erro Database!";
  24.     }
  25.  
  26. }
  27.    
  28. public boolean conectarDB() {
  29.  
  30.         try{
  31.             //Carrega o driver
  32.             Class.forName("org.postgresql.Driver");
  33.             String dbURL = "jdbc:postgresql://localhost:5432/database";
  34.             String user = "postgres";
  35.             String pass = "123456";
  36.             Connection conn = DriverManager.getConnection(dbURL, user, pass);
  37.  
  38.             if (conn != null) {
  39.                 return true;
  40.             } else {
  41.                 return true;
  42.             }
  43.  
  44.         } catch(Exception e){
  45.             e.printStackTrace();
  46.             return false;
  47.         }
  48.  
  49.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top