Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- try
- {
- // Doing some JDBC Connections here
- Map<String,Connection> connections = new HashMap<>();
- while(DeviceRS.next()){
- final String ip_address = DeviceRS.getString("Connection_vch");
- System.out.println("Value of the IP Address Field:"+ip_address);
- connections.put(ip_address,DriverManager.getConnection("jdbc:mysql://" + ip_address + ":3306/test",RemoteUser,RemotePass));
- }
- for(final String ip : connections.keySet())
- {
- // Selecting and inserting into database here ...
- }// ENd of for loop
- }// ENd of try block
- catch(SQLException ex){
- ex.printStackTrace();
- }
- // Doing some JDBC Connections here
- Map<String,Connection> connections = new HashMap<>();
- try
- {
- while(DeviceRS.next()){
- try{
- final String ip_address = DeviceRS.getString("Connection_vch");
- connections.put(ip_address,DriverManager.getConnection("jdbc:mysql://" + ip_address + ":3306/test",RemoteUser,RemotePass));
- }
- catch(SQLException ex){
- ex.printStackTrace();
- }
- }
- catch(Exception ex){
- ex.printStackTrace();
- System.out.println("in catch block");
- //System.exit(0); // dont use this -in real time projects
- }finally{
- System.out.println("in finally block");
- }
- for(final String ip : connections.keySet())
- {
- // Selecting and inserting into database here ...
- }// ENd of for loop
- }// ENd of try block
- try {
- // your code here
- for(final String ip : connections.keySet()) {
- try { // inner catch
- // your code, that will be continued if sql exception occurs
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- boolean check = true;
- while(check) {
- try {
- Map<String,Connection> connections = new HashMap<>();
- while(DeviceRS.next()){
- final String ip_address = DeviceRS.getString("Connection_vch");
- connections.put(ip_address,DriverManager.getConnection("jdbc:mysql://" + ip_address + ":3306/test",RemoteUser,RemotePass));
- } // Ends inner while
- check = false; //As connection is ok,we don't need to loop back.
- for(final String ip : connections.keySet())
- {
- // Selecting and inserting into database here ...
- }
- }// Ends try block
- catch(SQLException ex){
- ex.printStackTrace();
- } //Ends catch block
- finally{
- // close the connection if needed.
- } // Ends finally block
- }// Ends outer while loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement