java中判斷主鍵重複


SQLException中 e.getErrorCode() 获取sql server的系统错误代号

sqlServer錯誤代号:

2627 14 %1! 違反條件約束 ''%2!''。無法在物件 ''%4!'' 上插入重複索引鍵。

public boolean isPKError(SQLException e) {

    if (e == null) return false;

    int nErrCode = e.getErrorCode();

    if (nErrCode == 2627)

      return true;

    return false;

  }

转载于:https://my.oschina.net/dddgggaaa/blog/204923

猜你喜欢

转载自blog.csdn.net/weixin_34380296/article/details/92046892