mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
修正MySQL校验器的问题
1. 查询超时单位是秒,默认1000秒太长了,估计当时搞错单位了 2.当方法没有传SQL时设定一个默认的SQL,而不是直接返回true
This commit is contained in:
+6
-4
@@ -33,7 +33,8 @@ import com.alibaba.druid.util.Utils;
|
||||
|
||||
public class MySqlValidConnectionChecker extends ValidConnectionCheckerAdapter implements ValidConnectionChecker, Serializable {
|
||||
|
||||
public static final int DEFAULT_VALIDATION_QUERY_TIMEOUT = 1000;
|
||||
public static final int DEFAULT_VALIDATION_QUERY_TIMEOUT = 1;
|
||||
public static final String DEFAULT_VALIDATION_QUERY = "SELECT 1";
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final Log LOG = LogFactory.getLog(MySqlValidConnectionChecker.class);
|
||||
@@ -105,8 +106,9 @@ public class MySqlValidConnectionChecker extends ValidConnectionCheckerAdapter i
|
||||
}
|
||||
}
|
||||
|
||||
if (validateQuery == null || validateQuery.length() == 0) {
|
||||
return true;
|
||||
String query = validateQuery;
|
||||
if (validateQuery == null || validateQuery.isEmpty()) {
|
||||
query = DEFAULT_VALIDATION_QUERY;
|
||||
}
|
||||
|
||||
Statement stmt = null;
|
||||
@@ -116,7 +118,7 @@ public class MySqlValidConnectionChecker extends ValidConnectionCheckerAdapter i
|
||||
if (validationQueryTimeout > 0) {
|
||||
stmt.setQueryTimeout(validationQueryTimeout);
|
||||
}
|
||||
rs = stmt.executeQuery(validateQuery);
|
||||
rs = stmt.executeQuery(query);
|
||||
return true;
|
||||
} finally {
|
||||
JdbcUtils.close(rs);
|
||||
|
||||
Reference in New Issue
Block a user