get Tables from MySQL - Java JDBC

Java examples for JDBC:MySQL

Description

get Tables from MySQL

Demo Code


//package com.java2s;
import java.sql.Connection;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static List<String> getTables(Connection connection) {
        List<String> table_names = new ArrayList<String>();
        try {//from  w w  w. j  av  a 2s  .  c om
            ResultSet tables = connection.getMetaData().getTables(null,
                    null, null, new String[] { "TABLE" });
            while (tables.next()) {
                table_names.add(tables.getString(3));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return table_names;
    }
}

Related Tutorials