Here you can find the source of getTableNames(Connection conn)
public static Set<String> getTableNames(Connection conn) throws SQLException
//package com.java2s; //License from project: Open Source License import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.ResultSet; import java.sql.SQLException; import java.util.LinkedHashSet; import java.util.Set; public class Main { public static Set<String> getTableNames(Connection conn) throws SQLException { DatabaseMetaData dbmd = conn.getMetaData(); return getTableNames(conn, dbmd.getUserName()); }// ww w . j a v a 2 s .c o m public static Set<String> getTableNames(Connection conn, String schemaPattern) throws SQLException { DatabaseMetaData dbmd = conn.getMetaData(); Set<String> result = new LinkedHashSet<String>(); ResultSet rs = dbmd.getTables("", schemaPattern, "*", null); try { while (rs.next()) { result.add(rs.getString(3)); } } finally { rs.close(); } return result; } }