Advertisement
Guest User

Untitled

a guest
Jan 8th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. package agendaapp.model.database;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6.  
  7. /**
  8. *
  9. * @author Gustavo Leite
  10. */
  11. public class DatabaseConnection {
  12.  
  13. private static Connection connection;
  14.  
  15. private static String dsn = "jdbc:mysql://localhost:3306/agendaapp";
  16. private static String username = "root";
  17. private static String password = "root";
  18.  
  19. public static Connection getConnection() {
  20. if (connection == null) {
  21. try {
  22. connection = DriverManager.getConnection(dsn, username, password);
  23. } catch (SQLException ex) {
  24. System.out.println("Houve um erro ao conectar com o Banco de Dados.");
  25. }
  26. }
  27.  
  28. return connection;
  29. }
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement