Advertisement
Guest User

Untitled

a guest
May 26th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. package projetofinal;
  2.  
  3. import java.sql.Connection;
  4.  
  5. import java.sql.DriverManager;
  6.  
  7. import java.sql.SQLException;
  8.  
  9. public class ConexaoMysql {
  10.  
  11. public ConexaoMysql() {
  12. }
  13.  
  14. public static java.sql.Connection getConexaoMySQL() {
  15.  
  16.  
  17. try {
  18. String driverName = "com.mysql.jdbc.Driver";
  19. Class.forName(driverName);
  20. Connection connection = DriverManager.getConnection("jdbc:mysql://127.0.0.1/projetofinal", "root", "root");
  21. System.out.println("Conexao Bem Sucedida");
  22. return connection;
  23.  
  24.  
  25. } catch (ClassNotFoundException e) {
  26. System.out.println("O driver expecificado nao foi encontrado.");
  27. return null;
  28. } catch (SQLException e) {
  29. System.out.println("Nao foi possivel conectar ao Banco de Dados.");
  30. return null;
  31. }
  32. }
  33.  
  34. public static boolean FecharConexao() {
  35. try {
  36. ConexaoMysql.getConexaoMySQL().close();
  37. return true;
  38. } catch (SQLException e) {
  39.  
  40. return false;
  41.  
  42. }
  43.  
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement