sidneyrn3

Database

Sep 26th, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package dao;
  7.  
  8. import java.sql.Connection;
  9. import java.sql.DriverManager;
  10. import java.sql.PreparedStatement;
  11. import java.sql.ResultSet;
  12. import java.sql.SQLException;
  13. import java.sql.Statement;
  14. import java.util.ArrayList;
  15. import java.util.logging.Level;
  16. import java.util.logging.Logger;
  17.  
  18. /**
  19. *
  20. * @author sidney
  21. */
  22. public class Database {
  23. private String user = "root";
  24. private String password = "1234";
  25. private String db = "petshop";
  26. protected Connection connection;
  27.  
  28. public int connect() {
  29. try {
  30. Class.forName("com.mysql.jdbc.Driver");
  31. this.connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/"+db,this.user,this.password);
  32.  
  33. return 1;
  34. } catch(SQLException ex) {
  35. return 0;
  36. } catch(ClassNotFoundException x) {
  37. return 0;
  38. }
  39.  
  40. }
  41. public void desconectar() {
  42. try {
  43. this.connection.close();
  44. } catch (SQLException ex) {
  45.  
  46. }
  47. }
  48.  
  49.  
  50. }
Add Comment
Please, Sign In to add comment