Advertisement
Guest User

Untitled

a guest
Sep 28th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement