Files
Librography/src/br/com/projeto/jdbc/ConexaoBanco.java
T
2021-11-01 00:42:49 -03:00

78 lines
2.5 KiB
Java

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package br.com.projeto.jdbc;
import br.com.projeto.model.Utilitarios;
import br.com.projeto.view.FormOptions;
import com.mysql.jdbc.Connection;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.sql.DriverManager;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
/**
*
* @author Everton Luiz Kozloski - evertonkozloski@hotmail.com
*/
public class ConexaoBanco {
Utilitarios util = new Utilitarios();
public Connection pegarConexao() {
try {
String contentIP = null;
String ipserverPath = "";
String dbuserpPath = "";
String dbpassPath = "";
switch (util.getOS()) {
case WINDOWS:
ipserverPath = "C:\\Librography\\ipserver";
dbuserpPath = "C:\\Librography\\DBUser";
dbpassPath = "C:\\Librography\\DBPass";
break;
case MAC:
ipserverPath = "//Applications//Librography.app//config//ipserver";
dbuserpPath = "//Applications//Librography.app//config//DBUser";
dbpassPath = "//Applications//Librography.app//config//DBPass";
break;
case LINUX:
// some stuff
break;
}
try {
contentIP = new String(Files.readAllBytes(Paths.get(ipserverPath)));
} catch (IOException ex) {
Logger.getLogger(FormOptions.class.getName()).log(Level.SEVERE, null, ex);
}
String contentUser;
contentUser = new String(Files.readAllBytes(Paths.get(dbuserpPath)));
String contentPass;
contentPass = new String(Files.readAllBytes(Paths.get(dbpassPath)));
String url = "jdbc:mysql://" + contentIP + ":3306/gowl"; //Nome da base de dados
String user = contentUser; //nome do usuário do MySQL
String password = contentPass; //senha do MySQL
Connection conexao = null;
conexao = (Connection) DriverManager.getConnection(url, user, password);
return conexao;
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "erro" + e);
}
return null;
}
}