当我们使用jdbc 或者pdo或者其他mysql的驱动的时候,经常看到错误会有两个错误码 举个例子
Error number: 1005; Symbol: ER_CANT_CREATE_TABLE; SQLSTATE: HY000
1005
和HY000
或者是
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '34' for key 'PRIMARY',
23000
和1062
那么两者的关系是怎么样的呢?
Error code: This value is numeric. It is MySQL-specific and is not portable to other database systems.
SQLSTATE value: This value is a five-character string (for example, ‘42S02’). SQLSTATE values are taken from ANSI SQL and ODBC and are more standardized than the numeric error codes.
不管怎么样,你会看到两个错误一个是SQLSTATE
,一个是 errorcode
,两者区别就是SQLSTATE更加标准或者通用一些,而errorcode则是mysql自己的