Add DBHandler

AddSQL_DB
TechCrafter07 3 years ago
parent ac1c027a17
commit d7451301be

2
.gitignore vendored

@ -1 +1 @@
./config.json config.json

@ -23,6 +23,7 @@ repositories {
} }
dependencies { dependencies {
implementation 'org.jetbrains:annotations:20.1.0'
compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1' compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.13' compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.13'
testCompile group: 'junit', name: 'junit', version: '4.12' testCompile group: 'junit', name: 'junit', version: '4.12'

@ -1,5 +1,12 @@
{ {
"storePath": "./data/", "storePath": "./data/",
"apiURL": "https://data.sensor.community/airrohr/v1/sensor/35943/", "apiURL": "https://data.sensor.community/airrohr/v1/sensor/35943/",
"interval": 150 "interval": 150,
"sqlConnection": {
"db": "",
"pw": "",
"user": "",
"port": 3306,
"server": "localhost"
}
} }

@ -17,7 +17,7 @@ public class DataStore {
fw.close(); fw.close();
return true; return true;
}catch (IOException e){ }catch (IOException e){
System.out.println("error while soring data to: " + path); System.out.println("error while storing data to: " + path);
} }
return false; return false;
} }

@ -15,11 +15,13 @@ public class DataStoreBot {
String apiURL; String apiURL;
APIParser api; APIParser api;
DataStore store; DataStore store;
dbHandler db;
DataStoreBot(String storePath, String apiURL) throws MalformedURLException { DataStoreBot(String storePath, String apiURL) throws MalformedURLException {
this.storePath = storePath; this.storePath = storePath;
this.apiURL = apiURL; this.apiURL = apiURL;
this.api = new APIParser(this.apiURL); this.api = new APIParser(this.apiURL);
this.store = new DataStore(); this.store = new DataStore();
this.db = new dbHandler((JSONObject) store.readJSON("config.json").get("sqlConnection"));
} }
public void setInterval(int seconds) { public void setInterval(int seconds) {
ScheduledExecutorService ses = Executors.newScheduledThreadPool(1); ScheduledExecutorService ses = Executors.newScheduledThreadPool(1);

@ -0,0 +1,20 @@
package sh.adb.sensorCommunityAPI;
import org.json.simple.JSONObject;
public class dbHandler {
String pw;
String db;
String user;
int port;
String server;
dbHandler(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");
}
}
Loading…
Cancel
Save