code: private void validateDataSource(DataSource ds, String user, @Sensitive String password,
                                      LinkedHashMap<String, Object> result) throws SQLException {
          java.sql.Connection con = user == null ? ds.getConnection() : ds.getConnection(user, password);
  
          try {
              DatabaseMetaData metadata = con.getMetaData();
              result.put("databaseProductName", metadata.getDatabaseProductName());
              result.put("databaseProductVersion", metadata.getDatabaseProductVersion());
              result.put("driverName", metadata.getDriverName());
              result.put("driverVersion", metadata.getDriverVersion());
  
              try {
                  String catalog = con.getCatalog();
                  if (catalog != null && catalog.length() > 0)
                      result.put("catalog", catalog);
              } catch (SQLFeatureNotSupportedException ignore) {
              }
  
              try {
                  String schema = con.getSchema();
                  if (schema != null && schema.length() > 0)
                      result.put("schema", schema);
              } catch (SQLFeatureNotSupportedException ignore) {
              }
  
              String userName = metadata.getUserName();
              if (userName != null && userName.length() > 0)
                  result.put("user", userName);
  
              try {
                  boolean isValid = con.isValid(120); // TODO better ideas for timeout value?
                  if (!isValid)
                      result.put("failure", "FALSE returned by JDBC driver's Connection.isValid operation");
              } catch (SQLFeatureNotSupportedException x) {
              }
          } finally {
              con.close();
          }
      }
docs: Validate a connection factory that implements javax.sql.DataSource.
  
  @param ds       data source instance.
  @param user     user name, if any, that is specified in the header of the validation request.
  @param password password, if any, that is specified in the header of the validation request.
  @param result   validation result to which this method appends info.
  @throws SQLException if an error occurs.