Advertisement
Guest User

Untitled

a guest
Feb 1st, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. public class ConnectionFactory {
  2.  
  3. private String url = "jdbc:postgresql://localhost/banco";
  4. private String usuario = "usuario_banco";
  5. private String senha = "senha_usuario";
  6. String driver = "org.postgresql.Driver";
  7. Connection conexao;
  8.  
  9. /**
  10. * Metodo getConnection retorna uma conexao
  11. *
  12. * @return Connection que é uma conexao
  13. */
  14.  
  15. public Connection getConnection() {
  16. try {
  17. try {
  18. Class.forName(driver);
  19. } catch (ClassNotFoundException e) {
  20. e.printStackTrace();
  21. }
  22. conexao = DriverManager.getConnection(url, usuario, senha);
  23. return conexao;
  24. } catch (SQLException erro) {
  25. throw new RuntimeException(erro);
  26. }
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement