Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  1. import java.sql.DriverManager;
  2. import java.sql.SQLException;
  3.  
  4. import com.mysql.jdbc.Connection;
  5.  
  6.  
  7. public class SQL {
  8.    
  9.     private String usuario = "root";
  10.     private String password = "3487";
  11.     private String db = "stock";
  12.     private String server = "localhost";
  13.     private String url = "jdbc:mysql://"+server+"/"+db;
  14.     private Connection conexion = null;
  15.    
  16.     public Connection conectar() {
  17.        
  18.         try {
  19.             Class.forName("com.mysql.jdbc.Connection");
  20.             this.conexion = (Connection) DriverManager.getConnection(this.url,this.usuario,this.password);
  21.         }
  22.         catch(SQLException ex) {
  23.             System.out.println("Hubo un problema al intentar conectarse con la base de datos "+this.url);
  24.         }
  25.         catch(ClassNotFoundException ex) {
  26.             System.out.println(ex);
  27.         }
  28.         return this.conexion;
  29.     }
  30.    
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement