Search in sources :

Example 1 with MySQLSyntaxErrorException

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);
}
Also used : Connection(java.sql.Connection) MySQLSyntaxErrorException(com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException)

Example 2 with MySQLSyntaxErrorException

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;
}
Also used : Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) MySQLSyntaxErrorException(com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException) MySQLSyntaxErrorException(com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException) SQLException(java.sql.SQLException)

Example 3 with MySQLSyntaxErrorException

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());
}
Also used : Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) MySQLSyntaxErrorException(com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException)

Example 4 with MySQLSyntaxErrorException

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;
}
Also used : MySQLSyntaxErrorException(com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException) TestConnectDbResult(com.zrlog.common.type.TestConnectDbResult) MySQLSyntaxErrorException(com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException) ConnectException(java.net.ConnectException) ConnectException(java.net.ConnectException)

Aggregations

MySQLSyntaxErrorException (com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException)4 ResultSet (java.sql.ResultSet)2 Statement (java.sql.Statement)2 TestConnectDbResult (com.zrlog.common.type.TestConnectDbResult)1 ConnectException (java.net.ConnectException)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1