mysql 获取schema_如何获取数据库列表“Schema” MySql的名称使用java JDBC

bd96500e110b49cbb3cd949968f18be7.png

how to get list of Databases "Schema" names of MySql using java JDBC ?

解决方案

The getSchemas() method of the DatabaseMetaData is the obvious but with MySQL you have to use getCatalogs()

Example:

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") );

}


版权声明:本文为weixin_33657499原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。