Oracle用Properties 方式:参数oracle.net.CONNECT_TIMEOUT,单位ms
Properties props = new Properties();
props.put("oracle.net.CONNECT_TIMEOUT","5000");
Connection connection = DriverManager.getConnection(url, props);
MYSQL用url方式:参数是connectTimeout,单位是ms
jdbc:mysql://" + serviceIp + ":" + serviceProt +
"/" + serviceName + "?serverTimezone=GMT%2B8&useUnicode="
+ "true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull" +
"&connectTimeout=5000
Connection connection = DriverManager.getConnection(url, userName,PassWord);
SQLSERVER用url方式loginTimeout,单位是s
jdbc:sqlserver://" + serviceIp + ":" + serviceProt + ";DatabaseName=" + serviceName+
";loginTimeout=5
Connection connection = DriverManager.getConnection(url, userName, PassWord);
POSTGRESQL用url方式connectTimeout,单位是s
jdbc:postgresql://" + serviceIp + ":" + serviceProt + "/" + serviceName+"?connectTimeout=5
Connection connection = DriverManager.getConnection(url, userName, PassWord);