forked from marg-o/brigate
49 lines
1008 B
Java
49 lines
1008 B
Java
|
|
package dao;
|
|
|
|
import java.sql.Connection;
|
|
import java.sql.DriverManager;
|
|
import java.sql.SQLException;
|
|
import util.Config;
|
|
|
|
public class MySqlConnection {
|
|
|
|
Config cfg = new Config();
|
|
|
|
public static void main(String[] args) {
|
|
MySqlConnection c = new MySqlConnection();
|
|
c.open();
|
|
}
|
|
|
|
|
|
private Connection connection;
|
|
|
|
|
|
public Connection open() {
|
|
String nomeDriver = "com.mysql.jdbc.Driver";
|
|
String utente = cfg.getDbUser(); //nome utente
|
|
String password = cfg.getDbPass(); //password
|
|
String url = "jdbc:mysql://" + cfg.getDbHost() + ":" + cfg.getDbPort() + "/brigate?autoReconnect=true&useSSL=false";
|
|
|
|
try {
|
|
Class.forName(nomeDriver);
|
|
this.connection = DriverManager.getConnection(url, utente, password);
|
|
} catch (ClassNotFoundException e) {
|
|
e.printStackTrace();
|
|
} catch (SQLException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
return connection;
|
|
}
|
|
|
|
public void close() {
|
|
try {
|
|
connection.close();
|
|
} catch (SQLException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
}
|
|
}
|