Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package inyeccionsql;
- import java.sql.Connection;
- import java.sql.DriverManager;
- public class BD {
- private static Connection conexion = null;
- private static String host = "localhost";
- private static String port = "3306";
- private static String bd = "test";
- private static String user = "root";
- private static String password = "";
- // El constructor privado no permite que se generen clases
- private BD() {}
- public static Connection getConexion() {
- if (BD.conexion == null) {
- BD.conectar();
- }
- return BD.conexion;
- }
- private static void conectar() {
- try {
- DriverManager.registerDriver(new com.mysql.jdbc.Driver());
- BD.conexion = DriverManager.getConnection ("jdbc:mysql://" + BD.host + ":" + BD.port + "/" + BD.bd,
- BD.user,
- BD.password
- );
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement