add constructor to DBConfig

AddSQL_DB
adb 4 years ago
parent f5a54dfb74
commit f8d5295347

@ -13,14 +13,14 @@ public class DBConfig {
int port;
String server;
void setConfig(String pw, String db, String user, int port, String server){
DBConfig(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){
DBConfig(JSONObject config){
this.pw = (String) config.get("pw");
this.db = (String) config.get("db");
this.user = (String) config.get("user");

@ -28,8 +28,9 @@ public class DBHandler {
}
public void storeInDB(String country, int sensorID, String timeStamp, String value_type_p1, int id_p1, float value_p1, String value_type_p2, int id_p2, float value_p2, String allJSON) {
try (Statement stmt = this.connection.createStatement()) {
//stmt.executeUpdate("INSERT INTO apidata (id, country, sensorID, Timestamp, value_type_p1, id_p1, value_p1, value_type_p2, id_p2, value_p2, allJSON ) VALUES (0, " + country + ", " + sensorID + ", " + timeStamp + ", " + value_type_p1 + ", " + id_p1 + ", " + value_p1 + ", " + value_type_p2 + ", " + id_p2 + ", " + value_p2 + ", " + allJSON + ")");
stmt.executeUpdate("INSERT INTO apidata (id, country, sensorID, Timestamp, value_type_p1, id_p1, value_p1, value_type_p2, id_p2, value_p2, allJSON ) VALUES ( NULL , '" + country + "', " + sensorID + " , '" + timeStamp +"', '" + value_type_p1 + "', " + id_p1 + ", " + value_p1 + ", '" + value_type_p2 + "', " + id_p2 + " , " + value_p2 + " , '" + allJSON + "' )");
stmt.executeUpdate("" +
"INSERT INTO apidata (id, country, sensorID, Timestamp, value_type_p1, id_p1, value_p1, value_type_p2, id_p2, value_p2, allJSON )" +
"VALUES ( NULL , '" + country + "', " + sensorID + " , '" + timeStamp +"', '" + value_type_p1 + "', " + id_p1 + ", " + value_p1 + ", '" + value_type_p2 + "', " + id_p2 + " , " + value_p2 + " , '" + allJSON + "' )");
} catch (SQLException e) {
e.printStackTrace();

@ -11,8 +11,7 @@ public class Main {
JSONObject config = store.readJSON("config.json");
if (config == null) config = store.readJSON("example.config.json");
DBConfig dbConfig = new DBConfig();
dbConfig.setJsonConfig((JSONObject) config.get("dbConfig"));
DBConfig dbConfig = new DBConfig((JSONObject) config.get("dbConfig"));
DataStoreBot bot = new DataStoreBot(
config.get("storePath").toString(),

Loading…
Cancel
Save