Here you can find the source of getTables(DataSource datasource)
public static List<String> getTables(DataSource datasource) 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.List; import java.util.concurrent.CopyOnWriteArrayList; import javax.sql.DataSource; public class Main { private static List<String> _tnames = null; public static List<String> getTables(DataSource datasource) throws SQLException { if (_tnames != null) { return _tnames; }/* w w w .j a va 2s . co m*/ _tnames = new CopyOnWriteArrayList<String>(); Connection conn = null; ResultSet rs = null; try { conn = datasource.getConnection(); DatabaseMetaData dmd = conn.getMetaData(); String[] types = { "TABLE" }; // rs = dmd.getTables(conn.getCatalog(), conn.getSchema(), "%", types); rs = dmd.getTables(conn.getCatalog(), null, "%", types); while (rs.next()) { String tname = rs.getString("TABLE_NAME"); _tnames.add(tname); } } catch (Exception e) { e.printStackTrace(); } finally { if (conn != null) { conn.close(); } if (rs != null) { rs.close(); } } return _tnames; } }