Hi all!
I have several tables in an MsAccess db and I would like to read all data of a certain column to a Hashmap. With 3 tables and using static array, it' working but i have about 300 tables.
With the static array, I used sg like this:
id=1;
int array[] = {206,260,91}; //names of 3 tables
for (int i=0; i<3; i++)
{
int tables = array[i];
String sql = "SELECT * FROM "+tables+"";
try
{
PreparedStatement stat = con.prepareStatement (sql);
ResultSet rs = stat.executeQuery ();
Statement stmt2 = con.createStatement();
if (rs != null)
{
while (rs.next())
{
station = rs.getString("STATIONS");
boolean blnExists = hMap.containsValue(station);
if (blnExists == true)
{
System.out.println("Already exists " + station + ": " + blnExists);
}
else
{
hMap.put(id, station);
String sql_out = "INSERT INTO Stations_All(ID_STATION, STATION) VALUES(" + id + ", '" + station + "')";
stmt2.executeUpdate(sql_out);
id++;
System.out.println(hMap.values());
}
}
}
}
}
So this puts the stations of the 3 tables into both a hashmap and a new database(Stations_All). But what happens if I have several databases especially when the number of tables occasionally change? I haven't found a solution. I believe with the method number of tables should be determined and then somehow read all tables.
Any help is appreciated.