@Override
  @SuppressWarnings("nullness")
  public boolean write(String tableName, List<Map<String, Object>> rows)
      throws JDBCResourceManagerException {
    if (rows.size() == 0) {
      return false;
    }

    LOG.info("Attempting to write {} rows to {}.{}.", rows.size(), databaseName, tableName);

    try (Connection con = driver.getConnection(getUri(), username, password)) {
      Statement stmt = con.createStatement();

      for (Map<String, Object> row : rows) {
        List<String> columns = new ArrayList<>(row.keySet());
        StringBuilder sql =
            new StringBuilder("INSERT INTO ")
                .append(tableName)
                .append("(")
                .append(String.join(",", columns))
                .append(") VALUES (");

        List<String> valueList = new ArrayList<>();
        for (String colName : columns) {
          Object value = row.get(colName);
          if (value == null) {
            valueList.add(null);
          } else if (NumberUtils.isCreatable(value.toString())
              || "true".equalsIgnoreCase(value.toString())
              || "false".equalsIgnoreCase(value.toString())
              || value.toString().startsWith("ARRAY[")) {
            valueList.add(String.valueOf(value));
          } else {
            valueList.add("'" + value + "'");
          }
        }
        sql.append(String.join(",", valueList)).append(")");

        try {
          LOG.info("Running SQL statement: " + sql);
          stmt.executeUpdate(sql.toString());
        } catch (SQLException e) {
          throw new JDBCResourceManagerException(
              "Failed to insert values into table with SQL statement: " + sql, e);
        }
      }
      stmt.close();
    } catch (SQLException e) {
      throw new JDBCResourceManagerException(
          String.format("Exception occurred when trying to write records to %s.", tableName), e);
    }

    LOG.info("Successfully wrote {} rows to {}.{}.", rows.size(), databaseName, tableName);
    return true;
  }
@Test
  public void testWriteShouldThrowErrorWhenDriverFailsToEstablishConnection() throws SQLException {
    when(container.getHost()).thenReturn(HOST);
    when(container.getMappedPort(JDBC_PORT)).thenReturn(MAPPED_PORT);
    doThrow(SQLException.class).when(driver).getConnection(any(), any(), any());

    assertThrows(
        JDBCResourceManagerException.class,
        () -> testManager.write(TABLE_NAME, ImmutableList.of(ImmutableMap.of("key", "test"))));
  }