add timezone to mysql init

This commit is contained in:
Lukas Heiligenbrunner 2020-03-13 15:41:55 +01:00
parent 5605a813d9
commit 05b338ec85
3 changed files with 6 additions and 133 deletions

View File

@ -21,7 +21,7 @@ class MySQLConnector extends Database {
public Connection getConnection() throws SQLException {
DriverManager.setLoginTimeout(1);
return DriverManager.getConnection(
"jdbc:mysql://" + host + ":" + port + "/" + dbName + "?useSSL=false",
"jdbc:mysql://" + host + ":" + port + "/" + dbName + "?useSSL=false&serverTimezone=CET",
user,
password);
}

View File

@ -1,132 +0,0 @@
package com.wasteinformationserver.website.datarequests;
import com.wasteinformationserver.basicutils.Log;
import com.wasteinformationserver.db.JDBC;
import com.wasteinformationserver.website.basicrequest.PostRequest;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
/**
* todo
*
* @author Lukas Heiligenbrunner
*/
public class NewDateRequest extends PostRequest {
@Override
public String request(HashMap<String, String> params) {
StringBuilder sb = new StringBuilder();
JDBC jdbc;
ResultSet set;
try {
jdbc = JDBC.getInstance();
} catch (IOException e) {
Log.Log.error("no connection to db");
return "{\"query\" : \"nodbconn\"}";
}
switch (params.get("action")) {
case "getCitynames":
set = jdbc.executeQuery("select * from cities");
Log.Log.debug(set.toString());
sb.append("{\"data\":[");
try {
String prev = "";
while (set.next()) {
if (prev.equals(set.getString("name"))) {
} else {
if (!set.isFirst()) {
sb.append(",");
}
sb.append("{\"cityname\":\"" + set.getString("name") + "\"}");
}
prev = set.getString("name");
}
} catch (SQLException e) {
e.printStackTrace();
}
sb.append("]");
sb.append(",\"query\":\"ok\"");
sb.append("}");
Log.Log.debug(sb.toString());
break;
case "getzones":
set = jdbc.executeQuery("select * from cities WHERE `name`='" + params.get("cityname") + "' ORDER BY zone ASC");
Log.Log.debug(set.toString());
sb.append("{\"data\":[");
try {
int prev = 42;
while (set.next()) {
if (prev == set.getInt("zone")) {
} else {
sb.append("{\"zone\":\"" + set.getInt("zone") + "\"}");
if (!set.isLast()) {
sb.append(",");
}
}
prev = set.getInt("zone");
}
} catch (SQLException e) {
e.printStackTrace();
}
sb.append("]");
sb.append(",\"query\":\"ok\"");
sb.append("}");
break;
case "gettypes":
set = jdbc.executeQuery("select * from cities WHERE `name`='" + params.get("cityname") + "' AND `zone`='"+params.get("zonename")+"' ORDER BY zone ASC");
Log.Log.debug(set.toString());
sb.append("{\"data\":[");
try {
String prev = "42";
while (set.next()) {
if (prev == set.getString("wastetype")) {
} else {
sb.append("{\"wastetype\":\"" + set.getString("wastetype") + "\"}");
if (!set.isLast()) {
sb.append(",");
}
}
prev = set.getString("wastetype");
}
} catch (SQLException e) {
e.printStackTrace();
}
sb.append("]");
sb.append(",\"query\":\"ok\"");
sb.append("}");
break;
case "newdate":
sb.append("{");
Log.Log.debug(params);
set = jdbc.executeQuery("select * from cities WHERE `name`='" + params.get("cityname") + "' AND `zone`='" + params.get("zone") + "' AND `wastetype`='" + params.get("wastetype") + "'");
try {
set.last();
if (set.getRow() == 1) {
Log.Log.debug(set.getInt("id"));
int status = jdbc.executeUpdate("INSERT INTO `pickupdates`(`citywastezoneid`, `pickupdate`) VALUES ('" + set.getInt("id") + "','" + params.get("date") + "')");
if (status == 1) {
sb.append("\"status\" : \"success\"");
} else {
sb.append("\"status\" : \"error\"");
}
} else {
Log.Log.warning("city doesnt exist!");
sb.append("\"status\" : \"citydoesntexist\"");
}
} catch (SQLException e) {
e.printStackTrace();
}
sb.append(",\"query\":\"ok\"");
sb.append("}");
break;
}
return sb.toString();
}
}

View File

@ -8,6 +8,11 @@ import com.wasteinformationserver.website.basicrequest.PostRequest
import java.sql.ResultSet
import java.sql.SQLException
/**
* todo
*
* @author Lukas Heiligenbrunner
*/
class NewDateRequest : PostRequest() {
override fun request(params: HashMap<String, String>): String {
val sb = StringBuilder()