Discussion:
[h2] Check if an in-memory database exists
Nicholas DiMucci
2018-10-16 14:45:11 UTC
Permalink
Is there a way to check if an in-memory database already exists besides
just attempting to querying it?
--
You received this message because you are subscribed to the Google Groups "H2 Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to h2-database+***@googlegroups.com.
To post to this group, send email to h2-***@googlegroups.com.
Visit this group at https://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.
Nicholas DiMucci
2018-10-16 14:53:04 UTC
Permalink
And why I say "querying it" I mean doing a SELECT and seeing if the table
exists.
Post by Nicholas DiMucci
Is there a way to check if an in-memory database already exists besides
just attempting to querying it?
--
You received this message because you are subscribed to the Google Groups "H2 Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to h2-database+***@googlegroups.com.
To post to this group, send email to h2-***@googlegroups.com.
Visit this group at https://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.
Evgenij Ryazanov
2018-10-16 15:32:27 UTC
Permalink
Hello.

If you want to check presence of in-memory database you can add
;IFEXISTS=TRUE
to your database URL (something like
jdbc:h2:mem:database_name;IFEXISTS=TRUE).
With this argument an exception with error code 90013 will be thrown if
database is not exists.

If you want to check presence of a table in an opened database you can use
database metadata:
ResultSet rs = connection.getMetaData().getTables(null, "PUBLIC",
"TABLE_NAME", new String[] { "TABLE" });

if (rs.next) {


}
or a query from INFORMATION_SCHEMA.TABLES.
--
You received this message because you are subscribed to the Google Groups "H2 Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to h2-database+***@googlegroups.com.
To post to this group, send email to h2-***@googlegroups.com.
Visit this group at https://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.
Loading...