 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Retrieving MySQL Database structure information from Java?
Use DatabaseMetaData class to retrieve MySQL database structure. In this example, we will display all the table names of database “web” using Java with the help of getMetaData().
Following is the Java code −
Example
import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import com.mysql.jdbc.DatabaseMetaData; public class getDatabaseInformationDemo {    public static void main(String[] args) {       Connection con = null;       try {          con = DriverManager.getConnection("jdbc:mysql://localhost:3306/web?useSSL=false", "root", "123456");          DatabaseMetaData information = (DatabaseMetaData) con.getMetaData();          String allTableName[] = {             "TABLE"          };          ResultSet r = information.getTables(null, null, null, allTableName);          while (r.next()) {             System.out.println(r.getString(3));          }       }       catch (Exception e) {          e.printStackTrace();       }    } } This will produce the following output −
Output
demotable211 demotable212 demotable213 demotable214 demotable215 demotable216 name select
Advertisements
 