Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import com.mysql.jdbc.Connection;
- public class SQL {
- private String usuario = "root";
- private String password = "asdsadasd";
- private String db = "stock";
- private String server = "localhost";
- private String url = "jdbc:mysql://"+server+"/"+db;
- private Connection conexion = null;
- public Connection conectar() {
- try {
- Class.forName("com.mysql.jdbc.Connection");
- this.conexion = (Connection) DriverManager.getConnection(this.url,this.usuario,this.password);
- }
- catch(SQLException ex) {
- System.out.println("Hubo un problema al intentar conectarse con la base de datos "+this.url);
- }
- catch(ClassNotFoundException ex) {
- System.out.println(ex);
- }
- return this.conexion;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement