add class DBConfig
parent
302b89b14f
commit
f1c5199d89
@ -0,0 +1,35 @@
|
||||
package sh.adb.sensorCommunityAPI;
|
||||
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class DBConfig {
|
||||
String pw;
|
||||
String db;
|
||||
String user;
|
||||
int port;
|
||||
String server;
|
||||
|
||||
void setConfig(String pw, String db, String user, int port, String server){
|
||||
this.pw = pw;
|
||||
this.db = db;
|
||||
this.user = user;
|
||||
this.port = port;
|
||||
this.server = server;
|
||||
}
|
||||
void setJsonConfig(JSONObject config){
|
||||
this.pw = (String) config.get("pw");
|
||||
this.db = (String) config.get("db");
|
||||
this.user = (String) config.get("user");
|
||||
this.port = (Integer) config.get("port");
|
||||
this.server = (String) config.get("server");
|
||||
}
|
||||
Connection getDbConnection() throws SQLException {
|
||||
return DriverManager.getConnection(
|
||||
"jdbc:mariadb://"+this.server+":"+String.valueOf(this.port)+"/"+this.db+"?user="+this.user+"&password="+this.pw
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package sh.adb.sensorCommunityAPI;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class DBHandler {
|
||||
Connection connection;
|
||||
|
||||
DBHandler(DBConfig config) throws SQLException {
|
||||
this.connection = config.getDbConnection();
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package sh.adb.sensorCommunityAPI;
|
||||
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class dbHandler {
|
||||
String pw;
|
||||
String db;
|
||||
String user;
|
||||
int port;
|
||||
String server;
|
||||
Connection connection;
|
||||
|
||||
dbHandler(JSONObject config) throws SQLException {
|
||||
this.pw = (String) config.get("pw");
|
||||
this.db = (String) config.get("db");
|
||||
this.user = (String) config.get("user");
|
||||
this.port = (Integer) config.get("port");
|
||||
this.server = (String) config.get("server");
|
||||
Connection connection = DriverManager.getConnection(
|
||||
"jdbc:mariadb://"+this.server+":"+this.port+"/"+this.db+"?user="+this.user+"&password="+this.pw
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue