private boolean alreadyStarted(int port, String user, String pass) { new Str().classForName(Driver.class.getName()); Connection conn = null; String url = "jdbc:mysql://127.0.0.1:" + port + "/" + "?connectTimeout=150"; try { conn = DriverManager.getConnection(url, user, pass); return true; } catch (SQLException e) { if (e.getErrorCode() == MysqlErrorNumbers.ER_ACCESS_DENIED_ERROR && throwOnBadPassword) { throw new SQLRuntimeException(e); } return false; } catch (Exception e) { return false; } finally { try { if (conn != null) { conn.close(); } } catch (Exception e) { e.printStackTrace(); } } }
boolean canConnectToServer(int port, int milisecondsBeforeGivingUp) { int triesBeforeGivingUp = 1 + (milisecondsBeforeGivingUp / 1000) * 4; utils.str().classForName(Driver.class.getName()); Connection conn = null; String bogusUser = "Connector/MXJ"; String password = "Bogus Password"; String url = "jdbc:mysql://127.0.0.1:" + port + "/test" + "?connectTimeout=150"; for (int i = 0; i < triesBeforeGivingUp; i++) { try { conn = DriverManager.getConnection(url, bogusUser, password); return true; /* should never happen */ } catch (SQLException e) { if (e.getErrorCode() == MysqlErrorNumbers.ER_ACCESS_DENIED_ERROR) { return true; } } finally { try { if (conn != null) { conn.close(); } } catch (Exception e) { e.printStackTrace(err); } } utils.threads().pause(100); } return false; }
boolean canConnectToServer(int port, int milisecondsBeforeGivingUp) { int triesBeforeGivingUp = 1 + (milisecondsBeforeGivingUp / 1000) * 4; utils.str().classForName(Driver.class.getName()); Connection conn = null; String bogusUser = "Connector/MXJ";