如何使用Java JDBC获取MySql的数据库“模式”名称列表?
getSchemas()DatabaseMetaData 的方法很明显,但是对于MySQL,您必须使用getCatalogs()
getSchemas()
getCatalogs()
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()
例:
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") ); }