Here you can find the source of getDBTables(DatabaseMetaData metaData, String dataBase, String user)
Parameter | Description |
---|---|
metaData | DatabaseMetaData |
dataBase | String |
user | String |
Parameter | Description |
---|---|
SQLException | an exception |
public static String[] getDBTables(DatabaseMetaData metaData, String dataBase, String user) throws SQLException
//package com.java2s; //License from project: Apache License import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; public class Main { /**/* w w w . j av a 2 s.c o m*/ * * * @param conn Connection * @param user String * @param dataBase String * @return String[] * @throws SQLException */ public static String[] getDBTables(Connection conn, String user, String dataBase) throws SQLException { return getDBTables(conn.getMetaData(), dataBase, user); } /** * * * @param metaData DatabaseMetaData * @param dataBase String * @param user String * @return String[] * @throws SQLException */ public static String[] getDBTables(DatabaseMetaData metaData, String dataBase, String user) throws SQLException { ResultSet rs = metaData.getTables(dataBase, null, user, new String[] { "TABLE" }); List<String> tables = new ArrayList<String>(); try { while (rs.next()) { tables.add(rs.getString("TABLE_NAME")); } } finally { rs.close(); } String result[] = new String[tables.size()]; tables.toArray(result); return result; } }