Guest User

Untitled

a guest
Dec 2nd, 2017
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. private Persistencia() {
  2. base = BaseDatos.getInstancia();
  3. base.conectar("jdbc:mysql://localhost/dda", "root", "1234");
  4. }
  5.  
  6.  
  7. public void conectar(String url,String u,String p){
  8. try {
  9. conexion = DriverManager.getConnection(url, u, p);
  10. stmt = conexion.createStatement();
  11. } catch (SQLException ex) {
  12. System.out.println("Error al conectar:" + ex.getMessage());
  13. }
  14. }
  15.  
  16. public Connection conexion() {
  17. if (conexion == null) {
  18. try {
  19. Class.forName("com.mysql.jdbc.Driver");
  20. conexion= DriverManager.getConnection("jdbc:mysql://"+host+"/"+bd, usuario, contrasena);
  21. System.out.println("exito");
  22. } catch (ClassNotFoundException | SQLException ex) {
  23. Logger.getLogger(conexionBD.class.getName()).log(Level.SEVERE, null, ex);
  24. System.out.println("error");
  25. }
  26.  
  27. }
  28. return conexion;
  29. }
Add Comment
Please, Sign In to add comment