Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package undergroundpersist;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.io.IOException;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- public class ConexionBDRelacional {
- private Connection conn = null;
- private String userName;
- private String password;
- private String driver;
- private String url;
- private String ruta = "D:/Documents/Trabajo De Campo/UndergroundPersist/src/undergroundpersist/ConfiguracionBD.txt";
- Connection Connect() {
- try {
- File archivo = new File(ruta);
- FileReader lector = new FileReader(archivo);
- BufferedReader buffer = new BufferedReader(lector);
- userName = buffer.readLine();
- password = buffer.readLine();
- driver = buffer.readLine();
- url = buffer.readLine();
- // Conexion
- try {
- Class.forName(driver).newInstance(); // setup of the database driver
- conn = DriverManager.getConnection(url, userName, password); // creates the connection
- } catch (SQLException ex) {
- Logger.getLogger(Connection.class.getName()).log(Level.SEVERE, null, ex);
- } catch (ClassNotFoundException ex) {
- Logger.getLogger(Connection.class.getName()).log(Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- Logger.getLogger(Connection.class.getName()).log(Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- Logger.getLogger(Connection.class.getName()).log(Level.SEVERE, null, ex);
- }
- } catch (FileNotFoundException e) {
- System.out.println("No se encontro el archivo");
- } catch (IOException m) {
- System.out.println("No sepuede leer el archivo");
- }
- return conn;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement