admin管理员组

文章数量:1289362

When configuring a DB2 LUW connection in Spring Boot using Tomcat, I am seeing issues upon HADR failover where the alternate server is not properly failed over to. Post failover I receive SQLCODE=-1776 indicating the connection is attempting to be made to a standby database. A manual application restart resolves the issue as it will then connect to the alternate failover hostname, so I know the property configurations are working.

Below is the sample java code tested with:

    Connection conn = null;
    try {
      System.out.println("Connecting to the primary DB2 server...");
      Properties info = new Properties();
      info.put("user", DB_USER);
      info.put("password", password);
      info.put("clientRerouteAlternateServerName", CLIENT_REROUTE_ALTERNATE_SERVER_NAME);
      info.put("clientRerouteAlternatePortNumber", CLIENT_REROUTE_ALTERNATE_PORT_NUMBER);
      info.put("maxRetriesForClientReroute", MAX_RETRIES_FOR_CLIENT_REROUTE);
      info.put("retryIntervalForClientReroute", RETRY_INTERVAL_FOR_CLIENTREROUTE);
      info.put("enableSeamlessFailover", ENABLE_SEAMLESS_FAILOVER);

      conn = DriverManager.getConnection(JDBCURL, info);
      String hostName = getHostName(conn);
      return "Connected to "
          + conn.getMetaData().getDatabaseProductName()
          + " "
          + conn.getMetaData().getDatabaseProductVersion()
          + " "
          + HOST_NAME_LABEL
          + hostName;
    } catch (SQLException ex) {
      System.err.println("An error occurred during connection or query execution:");
      ex.printStackTrace();
      return "Failed to make connection!";
    } finally {
      if (conn != null) {
        try {
          conn.close();
          System.out.println("Connection closed.");
        } catch (SQLException e) {
          // Ignore closing errors
        }
      }
    }

I believe this issue may lie within Spring/Tomcat as replicating this code in plain Java + JDBC results in this issue going away with the alternate server properly failed over to. For more context, we had similar configurations using JNDI when connecting to our old WebSphere servers and did not see this issue.

I was wondering if anyone has experienced this issue before and has any resolution. Really trying to narrow down whether it whether there is incompatibility with this client rerouting HADR failover on Tomcat servers.

本文标签: spring bootTomcat causing issues with DB2 LUW Driver ConfigurationStack Overflow