From 05b338ec8511e5e9ef584c36692875cbd441dc21 Mon Sep 17 00:00:00 2001 From: Lukas Heiligenbrunner Date: Fri, 13 Mar 2020 15:41:55 +0100 Subject: [PATCH] add timezone to mysql init --- .../db/MySQLConnector.java | 2 +- .../website/datarequests/NewDateRequest.java | 132 ------------------ .../website/datarequests/NewDateRequest.kt | 5 + 3 files changed, 6 insertions(+), 133 deletions(-) delete mode 100644 src/java/com/wasteinformationserver/website/datarequests/NewDateRequest.java diff --git a/src/java/com/wasteinformationserver/db/MySQLConnector.java b/src/java/com/wasteinformationserver/db/MySQLConnector.java index 5f3cabc..2cba204 100755 --- a/src/java/com/wasteinformationserver/db/MySQLConnector.java +++ b/src/java/com/wasteinformationserver/db/MySQLConnector.java @@ -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); } diff --git a/src/java/com/wasteinformationserver/website/datarequests/NewDateRequest.java b/src/java/com/wasteinformationserver/website/datarequests/NewDateRequest.java deleted file mode 100644 index 1f1fb1b..0000000 --- a/src/java/com/wasteinformationserver/website/datarequests/NewDateRequest.java +++ /dev/null @@ -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 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(); - } -} diff --git a/src/java/com/wasteinformationserver/website/datarequests/NewDateRequest.kt b/src/java/com/wasteinformationserver/website/datarequests/NewDateRequest.kt index 222efd5..1b4114e 100644 --- a/src/java/com/wasteinformationserver/website/datarequests/NewDateRequest.kt +++ b/src/java/com/wasteinformationserver/website/datarequests/NewDateRequest.kt @@ -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 { val sb = StringBuilder()