I am retrieving tables from database. I am using the following code:
HashSet<String> hash = new HashSet<String>();
DatabaseMetaData md = conn.getMetaData();
ResultSet rs = md.getTables(null, null, "%", null);
while (rs.next()) {
hash.add(rs.getString(3));
}
I am getting each table twice as the output of this code. I am retrieving through hashset, but still I am getting each table twice. I want each table only one time.
Secondly, I want to use the tables stored in hashset to retrieve data from database. Which I am doing like this:
for (int i = 0; i < hash.size(); i++) {
sql="Select distinct a from hash.get(i)";
//now passing this to prepared statement and as usual taking resultset
}
But I run my application it shows that this does not exist, even when table is present in database. Please help me with both these scenarios.