Bug #15514 The SqlException should return a proper error code instead of zero
Submitted: 6 Dec 2005 8:49 Modified: 11 Nov 2009 2:36
Reporter: [ name withheld ] Email Updates:
Status: Won't fix Impact on me:
None 
Category:Connector / J Severity:S4 (Feature request)
Version:3.1.12 OS:Any (*)
Assigned to: CPU Architecture:Any

[6 Dec 2005 8:49] [ name withheld ]
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
[6 Dec 2005 11:18] Aleksey Kishkin
tescase

Attachment: Bug15514.java (text/x-java), 936 bytes.