De getSchemas()
methode van de DatabaseMetaData ligt voor de hand, maar met MySQL moet je getCatalogs()
gebruiken
http://download .oracle.com/javase/7/docs/api/java/sql/DatabaseMetaData.html#getSchemas() http://download .oracle.com/javase/7/docs/api/java/sql/DatabaseMetaData.html#getCatalogs()
Voorbeeld:
Class.forName("com.mysql.jdbc.Driver");
// change user and password as you need it
Connection con = DriverManager.getConnection (connectionURL, "user", "password");
ResultSet rs = con.getMetaData().getCatalogs();
while (rs.next()) {
System.out.println("TABLE_CAT = " + rs.getString("TABLE_CAT") );
}