Advertisement
Guest User

Untitled

a guest
Sep 18th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5. package br.unesp.demac.bcc.soo.agendaweb.util;
  6.  
  7. import java.sql.Connection;
  8. import java.sql.DriverManager;
  9. import java.sql.PreparedStatement;
  10. import java.sql.SQLException;
  11.  
  12. /**
  13. *
  14. * @author aluno
  15. */
  16. public class FabricaConexao implements Conexao {
  17.  
  18. private FabricaConexao() {
  19. }
  20.  
  21. public static Connection getConexao() {
  22. Connection con = null;
  23.  
  24. try {
  25. Class.forName(DRIVER);
  26. con = DriverManager.getConnection(URL, USER, PASSWORD);
  27. } catch (ClassNotFoundException ex) {
  28. System.out.println("Problemas ao carregar o Driver!");
  29. System.out.println("ERRO: " + ex.getMessage());
  30. } catch (SQLException ex) {
  31. System.out.println("Problemas ao autenticar!");
  32. System.out.println("ERRO: " + ex.getMessage());
  33. }
  34.  
  35. return con;
  36. }
  37.  
  38. public static void fechar(Connection con) {
  39. try {
  40. con.close();
  41. } catch (SQLException ex) {
  42. System.out.println("Problemas ao fechar: " + ex.getMessage());
  43. }
  44. }
  45.  
  46. public static void fechar(Connection con, PreparedStatement pstm) {
  47. try {
  48. con.close();
  49. pstm.close();
  50. } catch (SQLException ex) {
  51. System.out.println("Problemas ao fechar: " + ex.getMessage());
  52. }
  53. }
  54.  
  55. public static void fechar(PreparedStatement pstm) {
  56. try {
  57. pstm.close();
  58. } catch (SQLException ex) {
  59. System.out.println("Problemas ao fechar: " + ex.getMessage());
  60. }
  61. }
  62. }
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69. /*
  70. * To change this template, choose Tools | Templates
  71. * and open the template in the editor.
  72. */
  73.  
  74. package br.unesp.demac.bcc.soo.agendaweb.util;
  75.  
  76. /**
  77. *
  78. * @author aluno
  79. */
  80. public interface Conexao {
  81.  
  82. final String DATABASE = "agendaWeb";
  83.  
  84. final String DRIVER = "org.gjt.mm.mysql.Driver";
  85.  
  86. final String PASSWORD = "admin";
  87.  
  88. final String USER = "root";
  89.  
  90. final String URL = "jdbc:mysql://localhost:3306/" + DATABASE;
  91.  
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement