How do I have derby give me a list of available database names? I have
created two databases (sampleDB and testDB) in the directory pointed to
by my "derby.system.home" setting. Everything went fine, but I cannot
seem to find a way to have derby tell me what database names are there.
Here is the code I tried:
import java.sql.*;
import java.util.Properties;
/**
* DerbyMain
*/
public class DerbyMain {
public String driver = "org.apache.derby.jdbc.EmbeddedDriver";
public String protocol = "jdbc:derby:";
public String dbHome = "./databases";
public static void main(String[] args) {
new DerbyMain().go(args);
}
void go(String[] args) {
System.out.println("DerbyMain started");
try {
// Load the driver and boot all available databases
Properties sysProps = System.getProperties();
sysProps.put("derby.system.home", dbHome);
sysProps.put("derby.system.bootAll", new Boolean(true));
Class.forName(driver).newInstance();
System.out.println("Loaded the embedded driver.");
// Attempt to list the available databases
Properties props = new Properties();
DriverPropertyInfo[] info =
DriverManager.getDriver(protocol).getPropertyInfo(protocol, props);
// info[0] property should be database name
// choices field should be array of available database names
String[] choices = info[0].choices;
System.out.println("Found the following databases:");
for (int i = 0; i < choices.length; i++) {
System.out.println(choices[i]);
}
} catch (Throwable e) {
System.out.println("exception thrown:");
if (e instanceof SQLException) {
printSQLError((SQLException) e);
} else {
e.printStackTrace();
}
}
System.out.println("DerbyMain finished");
}
static void printSQLError(SQLException e) {
while (e != null) {
System.out.println(e.toString());
e = e.getNextException();
}
}
}
This program returns an empty array of strings. The documentation
implies that an array of available databases should be returned. What am
I doing wrong? Any help would be appreciated.
Bob Slomcenski