Here you can find the source of getTableNames(Connection conn)
static public List getTableNames(Connection conn) throws SQLException
//package com.java2s; //License from project: LGPL import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class Main { static public List getTableNames(Connection conn) throws SQLException { DatabaseMetaData dbmd = conn.getMetaData(); String[] types = new String[] { "TABLE", "VIEW" }; ResultSet rs = dbmd.getTables(null, null, null, types); List tables = null;/*from w w w . java 2 s .c o m*/ while (rs.next()) { String tableName = rs.getString("TABLE_NAME"); if (tables == null) { tables = new ArrayList(); } tables.add(tableName); } if (tables != null) { Collections.sort(tables); } return tables; } }