0

I need to connect my app on a mariadb server.
Here is the connection declaration:

Connection connection = DriverManager.getConnection("jdbc:mariadb://192.168.0.21:3306/smartbox?characterEncoding=utf8mb4",
                        "alan",
                        "motdepasse");

By following step by step execution I realise that a java.util.ConcurentModificationExeption comes in that method :

private static void mapPropertiesToOption(Builder builder, Properties properties) {
    Properties nonMappedOptions = new Properties();

    try {
      // Option object is already initialized to default values.
      // loop on properties,
      // - check DefaultOption to check that property value correspond to type (and range)
      // - set values
      Properties remainingProperties = new Properties();
      properties.forEach((key, val) -> remainingProperties.put(key, val));

      for (Field field : Builder.class.getDeclaredFields()) {
        if (remainingProperties.isEmpty()) break;
        for (final Object keyObj : remainingProperties.keySet()) {
          String realKey =
              OptionAliases.OPTIONS_ALIASES.get(keyObj.toString().toLowerCase(Locale.ROOT));
          if (realKey == null) realKey = keyObj.toString();
          final Object propertyValue = remainingProperties.get(keyObj);

          if (propertyValue != null && realKey != null) {
            if (realKey.toLowerCase(Locale.ROOT).equals(field.getName().toLowerCase(Locale.ROOT))) {
              field.setAccessible(true);
              remainingProperties.remove(keyObj);

              if (field.getGenericType().equals(String.class)
                  && !propertyValue.toString().isEmpty()) {
                field.set(builder, propertyValue);
              } else if (field.getGenericType().equals(Boolean.class)) {
                switch (propertyValue.toString().toLowerCase()) {
                  case "":
                  case "1":
                  case "true":
                    field.set(builder, Boolean.TRUE);
                    break;

                  case "0":
                  case "false":
                    field.set(builder, Boolean.FALSE);
                    break;

                  default:
                    throw new IllegalArgumentException(
                        String.format(
                            "Optional parameter %s must be boolean (true/false or 0/1) was '%s'",
                            keyObj, propertyValue));
                }
              } else if (field.getGenericType().equals(Integer.class)) {
                try {
                  final Integer value = Integer.parseInt(propertyValue.toString());
                  field.set(builder, value);
                } catch (NumberFormatException n) {
                  throw new IllegalArgumentException(
                      String.format(
                          "Optional parameter %s must be Integer, was '%s'",
                          keyObj, propertyValue));
                }
              }
            }
          }
        }
      }

after the first remainingProperties.remove(keyObj); when the code returns on line

for (final Object keyObj : remainingProperties.keySet()) I have the exception...

The code seems to find the three properties (user, database and characterencoding) and values.

Community
  • 1
  • 1

0 Answers0