JDBC-ODBC - Listing Tables with meta.GetTables()

This section describes how to get a list of tables in flat text file database connected by an ODBC driver.

From the previous tutorial, we know that the database represented by the ODBC driver based on flat text files is read-only. So I need to create some text files in the mapped directory. Each text file will be presented as a table by the ODBC driver.

To create 2 tables in the database represented by the DSN, HY_FLAT, I added two empty files in C:\local\ODBC_Flat_DB:

04/01/2007  06:31 PM                 0 Address.txt
04/01/2007  06:31 PM                 0 User.txt

The program below uses the getTables() method of the DatabaseMetaData to list all existing tables:

/* OdbcFlatListTables.java
 * Copyright (c) HerongYang.com. All Rights Reserved.
import java.sql.*;
public class OdbcFlatListTables {
  public static void main(String [] args) {
    Connection con = null;
    try {
      con = DriverManager.getConnection("jdbc:odbc:HY_FLAT");

      DatabaseMetaData meta = con.getMetaData();
      ResultSet res = meta.getTables(null, null, null,
         new String[] {"TABLE"});
      System.out.println("List of tables: ");
      while (res.next()) {
            "   "+res.getString("TABLE_CAT")
           + ", "+res.getString("TABLE_SCHEM")
           + ", "+res.getString("TABLE_NAME")
           + ", "+res.getString("TABLE_TYPE")
           + ", "+res.getString("REMARKS"));

    } catch (Exception e) {
      System.err.println("Exception: "+e.getMessage());

The output looks good:

herong> progra~1\java\jdk1.7.0_45\bin\javac

herong> progra~1\java\jdk1.7.0_45\bin\java OdbcFlatListTables

List of tables:
   C:\LOCAL\ODBC_FLAT_DB, null, Address.txt, TABLE, null
   C:\LOCAL\ODBC_FLAT_DB, null, User.txt, TABLE, null

So Microsoft ODBC Text Driver manages flat text files as a database with the following rules:

Table of Contents

 About This Book

 JDBC (Java Database Connectivity) Introduction

 JDK (Java SE) Installation

 Installing and Running Java DB - Derby

 Derby (Java DB) JDBC Driver

 Derby (Java DB) JDBC DataSource Objects

 Java DB (Derby) - DML Statements

 Java DB (Derby) - ResultSet Objects of Queries

 Java DB (Derby) - PreparedStatement

 MySQL Installation on Windows

 MySQL JDBC Driver (MySQL Connector/J)

 MySQL - PreparedStatement

 MySQL - Reference Implementation of JdbcRowSet

 MySQL - JBDC CallableStatement

 MySQL CLOB (Character Large Object) - TEXT

 MySQL BLOB (Binary Large Object) - BLOB

 Oracle Express Edition Installation on Windows

 Oracle JDBC Drivers

 Oracle - Reference Implementation of JdbcRowSet

 Oracle - PreparedStatement

 Oracle - JBDC CallableStatement

 Oracle CLOB (Character Large Object) - TEXT

 Oracle BLOB (Binary Large Object) - BLOB

 Microsoft SQL Server Express Edition

 Microsoft JDBC Driver for SQL Server

 Microsoft JDBC Driver - Query Statements and Result Sets

 Microsoft JDBC Driver - DatabaseMetaData Object

 Microsoft JDBC Driver - DDL Statements

 Microsoft JDBC Driver - DML Statements

 SQL Server - PreparedStatement

 SQL Server CLOB (Character Large Object) - TEXT

 SQL Server BLOB (Binary Large Object) - BLOB

 JDBC-ODBC Bridge Driver - sun.jdbc.odbc.JdbcOdbcDriver

JDBC-ODBC Bridge Driver - Flat Text Files

 JDBC-ODBC - Creating DSN for Flat Test File

 JDBC-ODBC - Connecting to Flat Text Files

 JDBC-ODBC - Getting Flat File Driver Info

 JDBC-ODBC - CREATE TABLE in Flat Text Files

JDBC-ODBC - Listing Tables with meta.GetTables()

 JDBC-ODBC - Tab Delimited Flat File Data

 JDBC-ODBC - ODBC Configuration for Flat Files

 JDBC-ODBC - Executing Queries on Flat Files

 JDBC-ODBC - Missing Flat Data Files

 JDBC-ODBC Bridge Driver - MS Access

 JDBC-ODBC Bridge Driver - MS SQL Server

 Summary of JDBC Drivers and Database Servers

 Using Connection Pool with JDBC

 Archived Tutorials


 Full Version in PDF/EPUB