I'm looking for information on how a database exists - from Java code - hsqldb and in Apache derby in Mysql It is quite easy because I can inquire with a system table - INFORMATION_SCHEMA.SCHEMATA
- but there are no such tables in these two databases
What is an option of mysql query? Is:
Selection from Information Science SCHEMA_NAME.SCHEMATA WHERE SCHEMA_NAME = & lt; Database & gt;
To know whether the database exists in hsqldb and apache derby?
A database exists or not
In a solution database URL, "ifexists = True "and try to open the database in such a way that if the database does not exist, you will get an exception. This works for HSQLDB and H2 databases, for Apache derby, add "make = wrong" (actually, just make sure there is no one "make = true"). "Make = false" also works for the H2 database, but not for HSQLDB (it's just ignored there). This "" ifexists = true "/"; Create = false "is the disadvantage of the trick: you will use exception handling for application flow control, which should be avoided (not only because the exception is slow to throw) Also, you will open a connection that you do not want. : HSQLDB 2.x seems to print the style trace in system.re (!) If the database does not exist and you "Except to throw exceptions"; Ifexists = true ".
You can check that the database file exists (s) This loss depends on how the database URL is mapped to a file name , Which depends on database type and database type, such as database interface and database version (!), And perhaps system properties. For the derby, you have to find out that the directory exists, and additionally "file.properties" (it seems) Like some files For HSQLDB, you can check that the file is the database name.Properties exist or not. For H2, check for the file name.H2.db with the current versions of Derby / HSUKDDB / H2, and the future Question:
The question is, why do you definitely need to know that the database already exists?
Whether a schema exists or not
Maybe you do not really see this Instead, you want to see if the given schema is present in the database or not, you
Pre> Contact Information Science SCHEMA_NAME.SCHEMATA WHERE SCHEMA_NAME = '& lt; SCHEMA NAME & gt; You can use.
This works for both HSQLDB (version 2.x) and H2. It works with other databases, is an exception derby, which does not support the standardized INFORMATION_SCHEMA schema.
Comments
Post a Comment