use of com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException in project searchcode-server by boyter.
the class SphinxSearchConfig method getConnection.
public Optional<Connection> getConnection(String server) throws SQLException {
Connection connection = null;
try {
connection = this.connectionList.getOrDefault(server, null);
if (connection == null || connection.isClosed() || !connection.isValid(1)) {
this.helpers.closeQuietly(connection);
Class.forName("com.mysql.jdbc.Driver");
var connectionString = (String) Properties.getProperties().getOrDefault("sphinx_connection_string", "jdbc:mysql://%s:9306?characterEncoding=utf8&maxAllowedPacket=1073741824&net_buffer_length=16384");
connectionString = String.format(connectionString, server);
connection = DriverManager.getConnection(connectionString, Values.EMPTYSTRING, Values.EMPTYSTRING);
this.connectionList.put(server, connection);
}
} catch (ClassNotFoundException ex) {
this.logger.severe(String.format("f9e4283d::error in class %s exception %s it appears searchcode is unable to connect sphinx using mysql connection as the driver is missing", ex.getClass(), ex.getMessage()));
} catch (MySQLSyntaxErrorException ex) {
this.logger.severe(String.format("2362eb21::error in class %s exception %s it appears searchcode is unable to connect sphinx", ex.getClass(), ex.getMessage()));
}
return Optional.ofNullable(connection);
}
use of com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException in project dal by ctripcorp.
the class MajorityHostValidator method doubleCheckValidate.
protected boolean doubleCheckValidate(Connection connection, String validateMemberId) throws SQLException {
try (Statement statement = connection.createStatement()) {
statement.setQueryTimeout(1);
try (ResultSet resultSet = statement.executeQuery(validateSQL1)) {
boolean flag = false;
StringBuilder message = new StringBuilder("validateMemberId:" + validateMemberId);
while (resultSet.next()) {
String memberId = resultSet.getString(Columns.MEMBER_ID.name());
String memberState = resultSet.getString(Columns.MEMBER_STATE.name());
String currentMemberId = resultSet.getString(Columns.CURRENT_MEMBER_ID.name());
message.append(String.format(DOUBLE_CHECK_VALIDATE_RESULT_DETAIL, memberId, memberState, currentMemberId));
if (validateMemberId.equalsIgnoreCase(memberId)) {
flag = MemberState.Online.name().equalsIgnoreCase(memberState);
}
}
LOGGER.info("doubleCheckValidate:" + message.toString());
return flag;
} catch (MySQLSyntaxErrorException e) {
LOGGER.warn(VALIDATE_COMMAND_DENIED, e);
LOGGER.logEvent(CAT_LOG_TYPE, VALIDATE_COMMAND_DENIED, e.getMessage());
return false;
}
} catch (Exception e) {
LOGGER.warn("error occured while doubleCheckValidate:", e);
}
return false;
}
use of com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException in project dal by ctripcorp.
the class MajorityHostValidator method validate.
protected ValidateResult validate(Connection connection, int clusterHostCount) throws SQLException {
boolean currentHostState = false;
String outputMemberId = "";
int onlineCount = 0;
StringBuilder message = new StringBuilder();
try (Statement statement = connection.createStatement()) {
statement.setQueryTimeout(1);
try (ResultSet resultSet = statement.executeQuery(validateSQL1)) {
while (resultSet.next()) {
String memberId = resultSet.getString(Columns.MEMBER_ID.name());
String currentMemberId = resultSet.getString(Columns.CURRENT_MEMBER_ID.name());
String memberState = resultSet.getString(Columns.MEMBER_STATE.name());
message.append(String.format(VALIDATE_RESULT_DETAIL, memberId, memberState, currentMemberId));
if (memberId.equals(currentMemberId)) {
outputMemberId = currentMemberId;
currentHostState = MemberState.Online.name().equalsIgnoreCase(memberState);
}
if (MemberState.Online.name().equalsIgnoreCase(memberState)) {
onlineCount++;
}
}
} catch (MySQLSyntaxErrorException e) {
LOGGER.warn(VALIDATE_COMMAND_DENIED, e);
LOGGER.logEvent(CAT_LOG_TYPE, VALIDATE_COMMAND_DENIED, e.getMessage());
return defaultValidateResult;
}
}
return currentHostState && 2 * onlineCount > clusterHostCount ? new ValidateResult(true, outputMemberId, message.toString()) : new ValidateResult(false, outputMemberId, message.toString());
}
use of com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException in project zrlog by 94fzb.
the class InstallService method testDbConn.
/**
* 尝试使用填写的数据库信息连接数据库
*/
public TestConnectDbResult testDbConn() {
TestConnectDbResult testConnectDbResult = null;
try {
Connection connection = getConnection();
connection.close();
testConnectDbResult = TestConnectDbResult.SUCCESS;
} catch (ClassNotFoundException e) {
LOGGER.error("", e);
testConnectDbResult = TestConnectDbResult.MISSING_MYSQL_DRIVER;
} catch (MySQLSyntaxErrorException e) {
LOGGER.error("", e);
if (e.getMessage().contains("Access denied for user ")) {
testConnectDbResult = TestConnectDbResult.DB_NOT_EXISTS;
}
} catch (SQLException e) {
LOGGER.error("", e);
if (e.getCause() instanceof ConnectException) {
testConnectDbResult = TestConnectDbResult.CREATE_CONNECT_ERROR;
} else {
testConnectDbResult = TestConnectDbResult.USERNAME_OR_PASSWORD_ERROR;
}
} catch (Exception e) {
LOGGER.error("", e);
testConnectDbResult = TestConnectDbResult.UNKNOWN;
}
return testConnectDbResult;
}
Aggregations