Home > Database > Mysql Tutorial > body text

How to Retrieve a List of Database Schemas in MySQL Using Java JDBC?

Patricia Arquette
Release: 2024-10-27 23:10:29
Original
229 people have browsed it

How to Retrieve a List of Database Schemas in MySQL Using Java JDBC?

Accessing Database Schemas in MySQL Using Java JDBC

Question: Retrieve a list of database schemas within a MySQL database using Java JDBC.

Response:

To obtain a list of database schemas, the getCatalogs() method of the DatabaseMetaData interface should be utilized. In the case of MySQL databases, the getCatalogs() method returns schema information instead of the term "schema."

<code class="java">Class.forName("com.mysql.jdbc.Driver");

// Modify user and password as needed
Connection con = DriverManager.getConnection (connectionURL, "user", "password");

ResultSet rs = con.getMetaData().getCatalogs();

while (rs.next()) {
    System.out.println("TABLE_CAT = " + rs.getString("TABLE_CAT") );
}</code>
Copy after login

This code demonstrates the process of connecting to a MySQL database and retrieving a list of schemas. Each schema will be printed to the console.

The above is the detailed content of How to Retrieve a List of Database Schemas in MySQL Using Java JDBC?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!