Actividad 2.2 CRUD sobre Pais - MapaMundi
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package org.palomafp.aadd.gdo;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Properties;
|
||||
|
||||
public class ConexionBD {
|
||||
|
||||
private static final String RUTA_CONFIG = "config/application.properties";
|
||||
|
||||
public static Connection getConexion() throws SQLException {
|
||||
Properties props = new Properties();
|
||||
try (FileInputStream fis = new FileInputStream(RUTA_CONFIG)) {
|
||||
props.load(fis);
|
||||
Class.forName(props.getProperty("sgdb.clase.driver"));
|
||||
} catch (IOException | ClassNotFoundException e) {
|
||||
throw new SQLException("Error cargando la configuración: " + e.getMessage(), e);
|
||||
}
|
||||
String url = props.getProperty("sgdb.conexion.url") + props.getProperty("bbdd.nombre");
|
||||
return DriverManager.getConnection(url,
|
||||
props.getProperty("bbdd.usuario"),
|
||||
props.getProperty("bbdd.clave"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user