Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5.  
  6. package conexao;
  7.  
  8. import com.mysql.jdbc.Connection;
  9. import com.mysql.jdbc.Statement;
  10. import java.sql.DriverManager;
  11. import java.sql.SQLException;
  12.  
  13. /**
  14. *
  15. * @author Mario Jorge
  16. */
  17. public class Conexao {
  18. private Connection conexao = null;
  19. private boolean status = false;
  20.  
  21. public Statement connect() throws SQLException {
  22. try {
  23. Class.forName("com.mysql.jdbc.Driver");
  24. conexao = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/livraria?user=root&password=");
  25. status = true;
  26. } catch (ClassNotFoundException ex) {
  27. ex.printStackTrace();
  28. status = false;
  29. return null;
  30. } catch (SQLException ex) {
  31. ex.printStackTrace();
  32. status = false;
  33. return null;
  34. }
  35. return (Statement) conexao.createStatement();
  36. }
  37.  
  38. public void disconect () {
  39. try {
  40. conexao.close();
  41. status = false;
  42. } catch (SQLException ex) {
  43. ex.printStackTrace();
  44. }
  45. }
  46.  
  47. public boolean isConnected() {
  48. return status;
  49. }
  50.  
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement