I have a program in Java which do some search operations on a database, this is the code:
public class DBSearch {
public static void SearchDatabase() throws Exception{
ArrayList<String> names = new ArrayList<String>();
Connection c = null;
PreparedStatement ps = null;
ResultSet rs = null;
String host = "localhost";
String db = "mydatabase";
String user = "root";
String password = "password";
Class.forName("com.mysql.jdbc.Driver");
c = DriverManager.getConnection("jdbc:mysql://"+host+"/" + db +"?user="+user+"&password="+password);
ps = c.prepareStatement("SELECT NAME FROM NAMES");
rs = ps.executeQuery();
names.clear()
while ( rs.next() ) {
names.add(rs.getString("NAME"));
}
for(i = 1; i < names.size(); i++){
//Do some database operations
Now what I want to do is that at the end of these operations, the process starts back making the same operations in another database. My idea was to create an ArrayList called dblist containing all the database names, and then doing something like this:
...
for(i=1, i < dblist.size(); i++{
Class.forName("com.mysql.jdbc.Driver");
c = DriverManager.getConnection("jdbc:mysql://"+host+"/" + dblist.get(i) +"?user="+user+"&password="+password);
But the process seems not to loop for each database, it works with only the first database in the array and than it stops.