code: public static boolean closeDataSource(DataSource ds) throws SQLException {
          try {
              Method closeMethod = ds.getClass().getMethod("close");
              try {
                  closeMethod.invoke(ds);
              } catch (Throwable e) {
                  ThrowUnchecked.fireFirstDeclaredCause(e, SQLException.class);
              }
              return true;
          } catch (NoSuchMethodException e) {
              return false;
          }
      }
docs: Attempts to close a DataSource by searching for a "close" method. For
  some reason, there's no standard way to close a DataSource.
  
  @return false if DataSource doesn't have a close method.