/** * 测试IP是否连通 Author zyx Date 2012-04-18 * * @param host * @return */ private boolean testHost(Map<String,String> props) { boolean status = false; // 设置验证IP连通延迟时间 int timeout = 3000; String url = props.get("url"); String dbtype = (String) Globals.SYS_DB_TYPE.get(props.get("name")); String host = ""; // 从url中截取IP连接地址 这里的截取方法 仅支持oracle sqlserver MysqL DB2 不支持sybase // 如果是oracle数据库 if ("1".equals(dbtype)) { if(url != null && !"".equals(url) && url.indexOf("@") > 0) host = url.substring(url.indexOf("@") + 1,url.indexOf(":",url.indexOf("@"))); } else { // 其他数据库 if(url != null && !"".equals(url) && url.indexOf("//") > 0) host = url.substring(url.indexOf("//") + 2,url.indexOf("//"))); } try { if (InetAddress.getByName(host).isReachable(timeout)) { logger.info("IP: " + host + " 正常连接"); status = true; } else { logger.info("IP: " + host + " 无法连接"); status = false; } } catch (UnkNownHostException e) { logger.info(host + "是非法的地址"); e.printstacktrace(); } catch (IOException e) { e.printstacktrace(); }