List tables in a database : Table « Database SQL JDBC « Java

List tables in a database

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;

public class Main {

  public static void main(String args[]) throws Exception {
    String URL = "jdbc:odbc:dbName";
    Connection conn = DriverManager.getConnection(URL, "user", "passw");

    DatabaseMetaData dmd = conn.getMetaData();
    ResultSet rs1 = dmd.getSchemas();
    while ( {
      String ss = rs1.getString(1);
      ResultSet rs2 = dmd.getTables(null, ss, "%", null);
      while (
        System.out.println(rs2.getString(3) + " " + rs2.getString(4));


Related examples in the same category

1.Table exist?
2.Listing All Table Names in a Database
3.Get all table schemas
4.Get all table catalogs
5.Another Method To Check Table Existance
6.Get Catalog Name From ResultSet Metadata
7.Get Available Table Name In A Database
8.Get Table Or View Name From A Database
9.Database metadata: data type
10.Deleting a Table from Database
11.Retrieving Tables from a Database
12.List the Tables in an SQL database
13.Copy One Database Table to Another
14.Create table with primary key
15.Create table with foreign key
16.Create data table 3
17.Create supplier table
18.Create data table: reference
19.Create data table 2
20.Creating a Database Table called my_table with one column, col_string, which holds strings.
21.Deleting a Database Table called my_table from a database.
22.Getting Rows from a Database Table
23.Getting the Number of Rows in a Database Table
24.Inserting a Row into a Database Table Using a Prepared Statement
25.Inserting a Row into a Database Table
26.Updating a Row in a Database Table
27.Deleting a Row from a Database Table
28.Deleting All Rows from a Database Table
29.Create data type and data table
30.Table and column existance