Description:
If I try to coonnect to mysql server with Java when the server is down I have a connection error obviously, with a SqlException; but the getErrorCode of the exception returns 0 and not the real mysql code corrisponding to that error.
If I open a console and I try to connect to mysql while the mysql server is down I get this message from mysql server:
ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)
In the Mysql Manual you can find the section titled:
Appendix B. Error Codes and Messages
where you can find all the errors code that mysql return when an error occurs, and for the code 2003 the manual says:
Error: 2003 (CR_CONN_HOST_ERROR)
Message: Can't connect to MySQL server on '%s' (%d)
so the SqlException should return the right error code, that is 2003, as it is specified in the mysql manual, instead of returning an anonymous "error code = 0" that you cannot use to figure what appened.
From the java api specification, SqlException:
public int getErrorCode()
Retrieves the vendor-specific exception code for this SQLException object.
Thanks
How to repeat:
Try to connect to mysql inside a java program when the server is down, catch the SqlException thrown and print the result of its getErrorCode
Suggested fix:
getErrorCode should return the right code for the error