Question: How can we iterate over the output of the query `show databases` in snowflake using JDBC. If there is another way to check if database is present or not over jdbc?

Answer: 
If the requirement is for validating the list of DB's and use it for some kind of audit purpose, you may can do the following:

1. First run the following command:

**show databases;**
2. Then use the result\_scan() function to get the DB name and the owner from the result of the previous command:

**select $2 as DB\_NAME, $6 as DB\_OWNER from table(result\_scan(last\_query\_id()));**
3. This list can be stored in new database table which is given access for other roles to check and validate.
you mean like:

```
select distinct database_name from information_schema.databases;

```