File tree Expand file tree Collapse file tree 2 files changed +12
-3
lines changed
src/main/java/com/github/shyiko/mysql/binlog Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -331,7 +331,14 @@ public void connect() throws IOException {
331331 throw new IOException ("Failed to connect to MySQL on " + hostname + ":" + port +
332332 ". Please make sure it's running." , e );
333333 }
334- GreetingPacket greetingPacket = new GreetingPacket (channel .read ());
334+ byte [] initialHandshakePacket = channel .read ();
335+ if (initialHandshakePacket [0 ] == (byte ) 0xFF /* error */ ) {
336+ byte [] bytes = Arrays .copyOfRange (initialHandshakePacket , 1 , initialHandshakePacket .length );
337+ ErrorPacket errorPacket = new ErrorPacket (bytes );
338+ throw new ServerException (errorPacket .getErrorMessage (), errorPacket .getErrorCode (),
339+ errorPacket .getSqlState ());
340+ }
341+ GreetingPacket greetingPacket = new GreetingPacket (initialHandshakePacket );
335342 authenticate (greetingPacket .getScramble (), greetingPacket .getServerCollation ());
336343 if (binlogFilename == null ) {
337344 fetchBinlogFilenameAndPosition ();
Original file line number Diff line number Diff line change @@ -31,8 +31,10 @@ public class ErrorPacket implements Packet {
3131 public ErrorPacket (byte [] bytes ) throws IOException {
3232 ByteArrayInputStream buffer = new ByteArrayInputStream (bytes );
3333 this .errorCode = buffer .readInteger (2 );
34- buffer .skip (1 ); // 1 byte for slash
35- this .sqlState = buffer .readString (5 );
34+ if (buffer .peek () == '#' ) {
35+ buffer .skip (1 ); // marker of the SQL State
36+ this .sqlState = buffer .readString (5 );
37+ }
3638 this .errorMessage = buffer .readString (buffer .available ());
3739 }
3840
You can’t perform that action at this time.
0 commit comments