Search in sources :

Example 6 with ErrorPacketException

use of com.alibaba.cobar.exception.ErrorPacketException in project cobar by alibaba.

the class MySQLChannel method sendCharset.

/**
 * 发送字符集设置
 */
private void sendCharset(int ci) throws IOException {
    // 发送命令: 直接写入到out中即可
    CommandPacket cmd = getCharsetCommand(ci);
    cmd.write(out);
    out.flush();
    BinaryPacket bin = receive();
    switch(bin.data[0]) {
        case OkPacket.FIELD_COUNT:
            this.charsetIndex = ci;
            this.charset = CharsetUtil.getCharset(ci);
            this.dbCharset = CharsetUtil.getCharset(ci);
            break;
        case ErrorPacket.FIELD_COUNT:
            ErrorPacket err = new ErrorPacket();
            err.read(bin);
            throw new ErrorPacketException(new String(err.message, charset));
        default:
            throw new UnknownPacketException(bin.toString());
    }
}
Also used : ErrorPacket(com.alibaba.cobar.net.mysql.ErrorPacket) ErrorPacketException(com.alibaba.cobar.exception.ErrorPacketException) UnknownPacketException(com.alibaba.cobar.exception.UnknownPacketException) CommandPacket(com.alibaba.cobar.net.mysql.CommandPacket) BinaryPacket(com.alibaba.cobar.net.mysql.BinaryPacket)

Aggregations

ErrorPacketException (com.alibaba.cobar.exception.ErrorPacketException)6 UnknownPacketException (com.alibaba.cobar.exception.UnknownPacketException)6 BinaryPacket (com.alibaba.cobar.net.mysql.BinaryPacket)6 ErrorPacket (com.alibaba.cobar.net.mysql.ErrorPacket)6 CommandPacket (com.alibaba.cobar.net.mysql.CommandPacket)4 UnknownCharsetException (com.alibaba.cobar.exception.UnknownCharsetException)1 HandshakePacket (com.alibaba.cobar.net.mysql.HandshakePacket)1 Reply323Packet (com.alibaba.cobar.net.mysql.Reply323Packet)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1