cloud-sql/mysql/servlet/src/main/java/com/example/cloudsql/functions/Main.java [93:123]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  private void submitVote(HttpRequest req, HttpResponse resp) throws IOException {
    DataSource pool = PoolHolder.getInstance();
    Timestamp now = new Timestamp(new Date().getTime());
    JsonObject body = gson.fromJson(req.getReader(), JsonObject.class);
    String team = Utils.validateTeam(body.get("team").getAsString());
    if (team == null) {
      resp.setStatusCode(400);
      resp.getWriter().append("Invalid team specified.");
      return;
    }
    try (Connection conn = pool.getConnection()) {
      // PreparedStatements can be more efficient and project against injections.
      String stmt = "INSERT INTO votes (time_cast, candidate) VALUES (?, ?);";
      try (PreparedStatement voteStmt = conn.prepareStatement(stmt);) {
        voteStmt.setTimestamp(1, now);
        voteStmt.setString(2, team);

        // Finally, execute the statement. If it fails, an error will be thrown.
        voteStmt.execute();
      }
    } catch (SQLException ex) {
      // If something goes wrong, handle the error in this section. This might involve retrying or
      // adjusting parameters depending on the situation.
      logger.log(Level.WARNING, "Error while attempting to submit vote.", ex);
      resp.setStatusCode(500);
      resp.getWriter()
          .write(
              "Unable to successfully cast vote! Please check the application "
                  + "logs for more details.");
    }
  }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



cloud-sql/sqlserver/servlet/src/main/java/com/example/cloudsql/functions/Main.java [93:123]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  private void submitVote(HttpRequest req, HttpResponse resp) throws IOException {
    DataSource pool = PoolHolder.getInstance();
    Timestamp now = new Timestamp(new Date().getTime());
    JsonObject body = gson.fromJson(req.getReader(), JsonObject.class);
    String team = Utils.validateTeam(body.get("team").getAsString());
    if (team == null) {
      resp.setStatusCode(400);
      resp.getWriter().append("Invalid team specified.");
      return;
    }
    try (Connection conn = pool.getConnection()) {
      // PreparedStatements can be more efficient and project against injections.
      String stmt = "INSERT INTO votes (time_cast, candidate) VALUES (?, ?);";
      try (PreparedStatement voteStmt = conn.prepareStatement(stmt);) {
        voteStmt.setTimestamp(1, now);
        voteStmt.setString(2, team);

        // Finally, execute the statement. If it fails, an error will be thrown.
        voteStmt.execute();
      }
    } catch (SQLException ex) {
      // If something goes wrong, handle the error in this section. This might involve retrying or
      // adjusting parameters depending on the situation.
      logger.log(Level.WARNING, "Error while attempting to submit vote.", ex);
      resp.setStatusCode(500);
      resp.getWriter()
          .write(
              "Unable to successfully cast vote! Please check the application "
                  + "logs for more details.");
    }
  }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



cloud-sql/postgres/servlet/src/main/java/com/example/cloudsql/functions/Main.java [93:123]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  private void submitVote(HttpRequest req, HttpResponse resp) throws IOException {
    DataSource pool = PoolHolder.getInstance();
    Timestamp now = new Timestamp(new Date().getTime());
    JsonObject body = gson.fromJson(req.getReader(), JsonObject.class);
    String team = Utils.validateTeam(body.get("team").getAsString());
    if (team == null) {
      resp.setStatusCode(400);
      resp.getWriter().append("Invalid team specified.");
      return;
    }
    try (Connection conn = pool.getConnection()) {
      // PreparedStatements can be more efficient and project against injections.
      String stmt = "INSERT INTO votes (time_cast, candidate) VALUES (?, ?);";
      try (PreparedStatement voteStmt = conn.prepareStatement(stmt);) {
        voteStmt.setTimestamp(1, now);
        voteStmt.setString(2, team);

        // Finally, execute the statement. If it fails, an error will be thrown.
        voteStmt.execute();
      }
    } catch (SQLException ex) {
      // If something goes wrong, handle the error in this section. This might involve retrying or
      // adjusting parameters depending on the situation.
      logger.log(Level.WARNING, "Error while attempting to submit vote.", ex);
      resp.setStatusCode(500);
      resp.getWriter()
          .write(
              "Unable to successfully cast vote! Please check the application "
                  + "logs for more details.");
    }
  }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



