Quantcast
Channel: MySQL Forums - Connector/J, JDBC and Java
Viewing all articles
Browse latest Browse all 884

how to control DriverManager.getConnection timeout period (2 replies)

$
0
0
Hi,
I use mysql ndb7.x, I try to write one simple java programe to detect when ndb can't be connected, but I found DriverManager.getConnection will not return but it will timeout after 20 minutes, so my programe can't tell me if connection can be setup or not until 20 minutes later. so I want to know how to control the DriverManager.getConnection timeout period, e.g. like 20 seconds. Or if there is a better way to detect Mysql ndb(cluster) can't be access through sqlnode. Thanks

my simple code is as below, your comments are highly appreciated,
Properties prop = new Properties();
prop.setProperty("connectTimeout", "5000");
prop.setProperty("socketTimeout", "5000");

return DriverManager.getConnection(
"jdbc:mysql:loadbalance://sc-1:3307,sc-2:3307/table?"
+ "localSocketAddress=xxxx", prop);

Viewing all articles
Browse latest Browse all 884

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>