Obtaining a List of MySQL Database Schema Names via Java JDBC
The JDBC API provides methods to retrieve information about the connected database schema. To retrieve a list of schema names in MySQL using Java JDBC, follow these steps:
The following code example demonstrates this process:
<code class="java">Class.forName("com.mysql.jdbc.Driver"); // Replace "connectionURL", "user", and "password" with appropriate values Connection con = DriverManager.getConnection(connectionURL, user, password); ResultSet rs = con.getMetaData().getCatalogs(); while (rs.next()) { System.out.println("CATALOG_NAME = " + rs.getString("TABLE_CAT")); }</code>
This code assumes you have loaded the MySQL JDBC driver and established a connection to the database. The output of the code will be a list of database schema names, or "CATALOG_NAME" in MySQL terminology.
The above is the detailed content of How to Retrieve a List of MySQL Database Schema Names Using Java JDBC?. For more information, please follow other related articles on the PHP Chinese website!