Use configs and mysql as default connector
This commit is contained in:
parent
fbbd2c2035
commit
5aeedf7adc
|
@ -12,7 +12,7 @@ import bean.Contatto;
|
|||
|
||||
public class ContattoDao implements ContattoDaoI {
|
||||
|
||||
OracleConnection c = new OracleConnection();
|
||||
MySqlConnection c = new MySqlConnection();
|
||||
|
||||
@Override
|
||||
public boolean create(String nome, String cognome, String servizio_sociale, String area, String indirizzo,
|
||||
|
|
|
@ -4,9 +4,12 @@ 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();
|
||||
|
@ -17,10 +20,10 @@ public class MySqlConnection {
|
|||
|
||||
|
||||
public Connection open() {
|
||||
String nomeDriver = "com.mysql.driverDriver";
|
||||
String utente = "brigate"; //nome utente
|
||||
String password = "password"; //password
|
||||
String url = "jdbc:oracle:thin:@localhost:1521:orcl";
|
||||
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);
|
||||
|
|
41
src/util/Config.java
Normal file
41
src/util/Config.java
Normal file
|
@ -0,0 +1,41 @@
|
|||
package util;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.*;
|
||||
import java.util.Properties;
|
||||
|
||||
|
||||
public class Config {
|
||||
Properties configFile;
|
||||
|
||||
public Config() {
|
||||
configFile = new java.util.Properties();
|
||||
try {
|
||||
configFile.load(this.getClass().getClassLoader().getResourceAsStream("/etc/brigate/brigate.conf"));
|
||||
} catch(FileNotFoundException ex) {
|
||||
System.out.println("Missing config file");
|
||||
}catch(Exception eta) {
|
||||
eta.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public String getDbUser() {
|
||||
String user = this.configFile.getProperty("db_user", "brigate");
|
||||
return user;
|
||||
}
|
||||
|
||||
public String getDbPass() {
|
||||
String pass = this.configFile.getProperty("db_password", "password");
|
||||
return pass;
|
||||
}
|
||||
|
||||
public String getDbHost() {
|
||||
String host = this.configFile.getProperty("db_url", "db");
|
||||
return host;
|
||||
}
|
||||
|
||||
public String getDbPort() {
|
||||
String port = this.configFile.getProperty("db_port", "3306");
|
||||
return port;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user