Please refer to following code:
Connection[] MainConnection = new Connection[7]; String[] RemoteIPAddress = new String[7]; RemoteIPAddress[0] = "aa.aa.a.aaa"; RemoteIPAddress[1] = "bb.bb.b.bbb"; RemoteIPAddress[2] = "cc.cc.c.ccc"; RemoteIPAddress[3] = "dd.dd.d.ddd"; RemoteIPAddress[4] = "ee.ee.e.eee"; RemoteIPAddress[5] = "ff.ff.f.fff"; RemoteIPAddress[6] = "gg.gg.g.ggg"; while(i<7) { try { Connection connRemote = DriverManager.getConnection("jdbc:mysql://xx.xx.x.xxx:3306/test",MainUser,MainPass); String maindbsql = "SELECT IP_vch FROM Maindb.TableIPStatus WHERE IPStatus = 1"; Statement stmt = connRemote.createStatement(); Resultset rs = stmt.executeQuery(maindbsql); while(rs.next()){ String ipAddress = rs.getString("IP_vch"); System.out.println("The value of ipAddress is:"+ipAddress); MainConnection[i] = DriverManager.getConnection("jdbc:mysql://" + RemoteIPAddress[i] + ":3306/test",RemoteUser,RemotePass); }// END Of WHILE (rs.next()) }catch(SQLException e){ e.printStackTrace(); } i++; } END OF ORIGINAL WHILE LOOP while (i < 7)
The output of the following statement :Therefore I wish to consider only these two IP addresses for opening connection on the following line:[b] System.out.println("The value of ipAddress is:"+ipAddress); [/b] is: bb.bb.b.bbb and cc.cc.c.ccc.But since I have already defined, RemoteIPAddress array from 0 - 6 at the start, the connection is getting opened for all the IP address. Please advise how can I restrict myself to some specific IP addresses as discussed above.MainConnection[i] = DriverManager.getConnection("jdbc:mysql://" + RemoteIPAddress[i] + ":3306/test",RemoteUser,RemotePass);
For reference, here is my database schema:
SQL Fiddle
Thanks