// 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) {
        for(String constr1 : constr) {
            try(Connection con = DriverManager.getConnection(constr1, un, pw)) {
                // do something with connection
                return constr1 + " worked";
            } catch (SQLException e) {
                // nothing => go next connection string
            }
        }
        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);
    }
}
