Right now, I have something like the following in my try block:
try { connRemote = DriverManager.getConnection("jdbc:mysql://xx.xx.x.xxx:3306/test",MainUser,MainPass); String maindbsql = null; maindbsql = "SELECT IP_vch FROM Mytableinxx_xx_x-xxx WHERE IPStatus = 1 "; // Let's says the result fo the query is aa.aa.a.aaa,bb.bb.b.bbb out of 10 IP Addresses present over there. Map<String,Connection> connections = new HashMap<>(); DeviceStmt = connRemote.createStatement(); DeviceRS = DeviceStmt.executeQuery(maindbsql); while(DeviceRS.next()){ final String ip_address = DeviceRS.getString("IP_vch"); System.out.println("Value of IP_vch Field:"+ip_address); connections.put(ip_address,DriverManager.getConnection("jdbc:mysql://" + ip_address + ":3306/test",RemoteUser,RemotePass)); if(connections.isEmpty()){ System.err.println("Status not set to 1 for any of the databases"); } }//END Of while(DeviceRS.next()) String QueryString = "SELECT query goes here"; SelectResultsStmt = (Don't know what to put here?).createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); SelectResultsRS = SelectResultsStmt.executeQuery(QueryString); }//ENd Of Try block catch(SQLException ex){ ex.printStackTrace(); }
So, for each of the IPAddresses that I got above in the `maindbsql`, that is `aa.aa.a.aaa` and `bb.bb.b.bbb` I want to call the `createStatement()` method in the following line mentioned in the above code:
SelectResultsStmt = (Don't know what to put here?).createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
Since, while establishing connection to these two IPAddresses, I am using `connections.put()` method as follows in the above code:
connections.put(ip_address,DriverManager.getConnection("jdbc:mysql://" + ip_address + ":3306/test",RemoteUser,RemotePass));
I don't have anything like Connection object `connRemote` that I have used for `xx.xx.x.xxx`, for my IP addresses aa.aa.a.aaa and bb.bb.b.bbb .
Could anyone please let me know if there is any way to overcome this problem?
Please let me know if I can answer any questions from my end.
P.S: The IP addresses I have used in my real code are IPV4 addresses and not alphabets.