add mariadb-java-client

AddSQL_DB
adb 4 years ago
parent d7451301be
commit 302b89b14f

@ -26,6 +26,7 @@ dependencies {
implementation 'org.jetbrains:annotations:20.1.0' 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'
compile group: 'org.mariadb.jdbc', name: 'mariadb-java-client', version: '2.7.2'
testCompile group: 'junit', name: 'junit', version: '4.12' testCompile group: 'junit', name: 'junit', version: '4.12'
} }

@ -6,6 +6,7 @@ import org.json.simple.parser.ParseException;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.sql.SQLException;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -16,7 +17,7 @@ public class DataStoreBot {
APIParser api; APIParser api;
DataStore store; DataStore store;
dbHandler db; dbHandler db;
DataStoreBot(String storePath, String apiURL) throws MalformedURLException { DataStoreBot(String storePath, String apiURL) throws MalformedURLException, SQLException {
this.storePath = storePath; this.storePath = storePath;
this.apiURL = apiURL; this.apiURL = apiURL;
this.api = new APIParser(this.apiURL); this.api = new APIParser(this.apiURL);

@ -2,6 +2,9 @@ package sh.adb.sensorCommunityAPI;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class dbHandler { public class dbHandler {
String pw; String pw;
@ -9,12 +12,16 @@ public class dbHandler {
String user; String user;
int port; int port;
String server; String server;
Connection connection;
dbHandler(JSONObject config){ dbHandler(JSONObject config) throws SQLException {
this.pw = (String) config.get("pw"); this.pw = (String) config.get("pw");
this.db = (String) config.get("db"); this.db = (String) config.get("db");
this.user = (String) config.get("user"); this.user = (String) config.get("user");
this.port = (Integer) config.get("port"); this.port = (Integer) config.get("port");
this.server = (String) config.get("server"); 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…
Cancel
Save