You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
999 B
Java
36 lines
999 B
Java
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;
|
|
|
|
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;
|
|
}
|
|
DBConfig(JSONObject config){
|
|
this.pw = (String) config.get("pw");
|
|
this.db = (String) config.get("db");
|
|
this.user = (String) config.get("user");
|
|
this.port = (int) (long) 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
|
|
);
|
|
}
|
|
}
|