// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;

public class MultiTry {
    public static String test(List<String> constr, String un, String pw) {
        try(Connection con = DriverManager.getConnection(constr.get(0), un, pw)) {
            // do something with connection
            return constr.get(0) + " worked";
        } catch (SQLException e) {
            if(constr.size() > 1) {
                return test(constr.subList(1, constr.size()) , un, pw);
            } else {
                return "Houston we got a problem";
            }
        }
    }
    public static void main(String[] args) {
        String res = test(Arrays.asList("jdbc:mysql://localhost:3308/Test", "jdbc:mysql://localhost:3307/Test", "jdbc:mysql://localhost:3306/Test"), "root", "");
        System.out.println(res);
    }
}
