当我尝试在表中插入一行时出现以下错误:
com.microsoft.sqlserver.jdbc.SQLServerException:违反PRIMARY密钥约束'PK_EM_SCHEDULER_POLLS'。无法在其中插入重复的密钥对象“ dbo.EM_SCHEDULER_POLLS”。重复的键值为(109303)。
导致错误的函数如下:
public boolean setPollResults(int nSchedulerControllerPollId, Date dtExecuted, boolean blnSuccess)
{
try
{
PreparedStatement stmt = null;
String strSQL;
strSQL = "INSERT INTO EM_SCHEDULER_POLLS (SCHEDULER_CONTROLLER_POLL_ID ,DATE_TIME_EXECUTED ,POLLED_SUCCESSFULLY) VALUES (?,?,?)";
stmt = this.getConnection().getConnection().prepareStatement(strSQL);
stmt.setInt(1,nSchedulerControllerPollId);
stmt.setTimestamp(2, new Timestamp( dtExecuted.getTime()));
stmt.setBoolean(3,blnSuccess);
boolean blnValue = stmt.executeUpdate()!=0;
stmt.close();
return blnValue;
}
catch (Exception ex)
{
if (Logger.isErrorEnabled())
Logger.error(ex);
}
return false;
}
此表设计。如您所见,我没有尝试在标识类型的ID列中插入值。表中已经存在重复值109303,但是为什么再次生成该值?