Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- */
- public class AbrirBaseDeDatos {
- private Connection con = null; //crea objeto conexion nulo
- private String baseDeDatos;
- private String user;
- private String pass;
- private String url;
- public AbrirBaseDeDatos(){}
- public Connection conectar(String baseDeDatos) throws Exception{
- try {
- String user = new String("root"); // el root de mysql
- String pass = new String(""); //passwd del mysql
- String url = "jdbc:mysql://localhost:3306/"+baseDeDatos;
- Class.forName("com.mysql.jdbc.Driver").newInstance();//declaración del driver para conectarse
- con = DriverManager.getConnection(url,user,pass); //este conecta
- }
- catch (SQLException sqle)
- {
- System.out.println("Error SQL.....conexion" +sqle);
- }
- if ( con != null )
- System.out.println("Se ha establecido una conexión a la base de datos ");
- return con;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement