Path: csiph.com!aioe.org!.POSTED.O5hsyUvK01te0L/SZurVSQ.user.gioia.aioe.org!not-for-mail From: =?UTF-8?Q?Arne_Vajh=c3=b8j?= Newsgroups: comp.lang.java.programmer Subject: Re: Does this make sense? Date: Fri, 5 Apr 2019 12:31:56 -0400 Organization: Aioe.org NNTP Server Lines: 40 Message-ID: References: <636ed842-3212-4955-8c81-0a48f162b6b9@googlegroups.com> NNTP-Posting-Host: O5hsyUvK01te0L/SZurVSQ.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 Content-Language: en-US X-Notice: Filtered by postfilter v. 0.9.2 Xref: csiph.com comp.lang.java.programmer:38874 On 4/5/2019 11:39 AM, Eric Douglas wrote: > On Thursday, April 4, 2019 at 8:33:50 PM UTC-4, Arne Vajhøj wrote: >> return test(constr.subList(1, constr.size()) , un, pw); >> } else { >> return "Houston we got a problem"; >> } > > Interesting solution, I would not have thought to use recursion for that but it works. You could also use a loop. 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 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); } } Arne