40 lines
1.2 KiB
Java
40 lines
1.2 KiB
Java
package org.palomafp.aadd.rmr.config;
|
|
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.sql.Connection;
|
|
import java.sql.DriverManager;
|
|
import java.sql.SQLException;
|
|
import java.util.Properties;
|
|
|
|
public class ConexionBD {
|
|
|
|
private static final String FICHERO = "application.properties";
|
|
|
|
private static Properties cargarPropiedades() throws IOException {
|
|
Properties propiedades = new Properties();
|
|
InputStream entrada = null;
|
|
try {
|
|
entrada = ConexionBD.class.getClassLoader().getResourceAsStream("application.properties");
|
|
propiedades.load(entrada);
|
|
} catch (IOException e) {
|
|
e.getMessage();
|
|
} finally {
|
|
if (entrada != null) {
|
|
entrada.close();
|
|
}
|
|
}
|
|
return propiedades;
|
|
}
|
|
|
|
public static Connection obtenerConexion() throws IOException, SQLException {
|
|
Properties propiedades = cargarPropiedades();
|
|
|
|
// estos nombres tienen que coincidir con el de application.properties
|
|
String url = propiedades.getProperty("sgdb.conexion.url") + propiedades.getProperty("bbdd.nombre");
|
|
String usuario = propiedades.getProperty("bbdd.usuario");
|
|
String pass = propiedades.getProperty("bbdd.pass");
|
|
|
|
return DriverManager.getConnection(url, usuario, pass);
|
|
}
|
|
} |