Advertisement
Guest User

Untitled

a guest
Jun 20th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. */
  2. public class AbrirBaseDeDatos {
  3. private Connection con = null; //crea objeto conexion nulo
  4. private String baseDeDatos;
  5. private String user;
  6. private String pass;
  7. private String url;
  8.  
  9.  
  10. public AbrirBaseDeDatos(){}
  11.  
  12.  
  13.  
  14.  
  15. public Connection conectar(String baseDeDatos) throws Exception{
  16. try {
  17. String user = new String("root"); // el root de mysql
  18.  
  19. String pass = new String(""); //passwd del mysql
  20.  
  21. String url = "jdbc:mysql://localhost:3306/"+baseDeDatos;
  22.  
  23. Class.forName("com.mysql.jdbc.Driver").newInstance();//declaración del driver para conectarse
  24.  
  25. con = DriverManager.getConnection(url,user,pass); //este conecta
  26. }
  27. catch (SQLException sqle)
  28. {
  29. System.out.println("Error SQL.....conexion" +sqle);
  30. }
  31.  
  32. if ( con != null )
  33. System.out.println("Se ha establecido una conexión a la base de datos ");
  34.  
  35. return con;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement