连接Mysql的时候,设置连接超时限制DriverManager.setLoginTimeout(10);不管用

转载梵高的夏天

连接数据库(MySql)的时候, 设置连接超时,这种方法不起作用
DriverManager.setLoginTimeout(10); 
connection = (Connection) DriverManager.getConnection( 
"jdbc:mysql://" + ServiceIP + "/mydb", "user", "456"); 

使用这种方式设置连接超时
jdbc:mysql://127.0.0.1:3066/test?connectTimeout=3000&socketTimeout=60000

HTTP请求时connectionRequestTimeout 、connectionTimeout、socketTimeout三个超时时间的含义:
connectionRequestTimout:指从连接池获取连接的timeout
connetionTimeout:指客户端和服务器建立连接的timeout就是http请求的三个阶段,一:建立连接;二:数据传送;三,断开连接。超时后会ConnectionTimeOutException
socketTimeout:指客户端从服务器读取数据的timeout,超出后会抛出SocketTimeOutException

你可能感兴趣的:(android日常小知识)