The detection code is checking against SQL error code, even though
the SQL state is retrieved from the SQLException. As the consequence,
duplicate key state is not detected and primary key violation error
is reported during REST API call.
To rectify, retrieve the error code number from the SQL exception to
correctly detect duplicate key error. This approach is also based on
gwtorm code that is also using SQLException#getErrorCode() method.
Bug: Issue 10664
Change-Id: I678419a84af287edd8d121bddd2d11c2ed72eefe