Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #38874
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Does this make sense? |
| Date | 2019-04-05 12:31 -0400 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <q87vu2$7tv$1@gioia.aioe.org> (permalink) |
| References | (2 earlier) <c001151d-044c-4d1b-ad88-0efd923e4433@googlegroups.com> <q85699$oq6$1@dont-email.me> <b8961ec3-eac5-45da-aa5d-11144bcae219@googlegroups.com> <q867p2$gv3$1@gioia.aioe.org> <636ed842-3212-4955-8c81-0a48f162b6b9@googlegroups.com> |
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<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);
}
}
Arne
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Does this make sense? Eric Douglas <e.d.programmer@gmail.com> - 2019-04-04 05:22 -0700
Re: Does this make sense? Eric Sosman <esosman@comcast-dot-net.invalid> - 2019-04-04 09:03 -0400
Re: Does this make sense? Eric Douglas <e.d.programmer@gmail.com> - 2019-04-04 07:02 -0700
Re: Does this make sense? Eric Sosman <esosman@comcast-dot-net.invalid> - 2019-04-04 11:01 -0400
Re: Does this make sense? Eric Douglas <e.d.programmer@gmail.com> - 2019-04-04 08:21 -0700
Re: Does this make sense? Eric Douglas <e.d.programmer@gmail.com> - 2019-04-04 11:45 -0700
Re: Does this make sense? Arne Vajhøj <arne@vajhoej.dk> - 2019-04-04 20:33 -0400
Re: Does this make sense? Eric Douglas <e.d.programmer@gmail.com> - 2019-04-05 08:39 -0700
Re: Does this make sense? Arne Vajhøj <arne@vajhoej.dk> - 2019-04-05 12:31 -0400
Re: Does this make sense? bursejan@gmail.com - 2019-04-05 10:53 -0700
Re: Does this make sense? bursejan@gmail.com - 2019-04-05 10:57 -0700
Re: Does this make sense? bursejan@gmail.com - 2019-04-05 11:02 -0700
Re: Does this make sense? bursejan@gmail.com - 2019-04-05 11:13 -0700
Re: Does this make sense? Patrick Roemer <sangamon@netcologne.de> - 2019-04-05 17:43 +0200
Re: Does this make sense? Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2019-04-07 22:14 +0200
Re: Does this make sense? Andreas Leitgeb <avl@logic.at> - 2019-04-04 15:15 +0000
csiph-web