Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement