java.sql.SQLIntegrityConstraintViolationException: ORA-00001
java.sql.SQLIntegrityConstraintViolationException: ORA-00001
下面是我的 java 代码的一部分,我们用它来将记录插入 table。
public void insertitem(long item_id, long user_id) throws SQLException
{
PreparedStatement pstmt = null;
StringBuffer sqlB = new StringBuffer();
sqlB.append("INSERT INTO ITEMS ");
sqlB.append("(AIR_ID, ACT_ITEM_ID, USER_ID) ");
sqlB.append(" VALUES ");
sqlB.append("(ITEMS_SEQ.nextval,?,?) ");
try
{
pstmt = conn.prepareStatement(sqlB.toString());
int i=1;
pstmt.setLong(i, item_id);i++;
pstmt.setLong(i, user_id);i++;
pstmt.executeUpdate();
}
catch(SQLException e)
{
throw new SQLException(e.getMessage());
}
}
即使我使用 SEQ.nextval,它仍然会抛出以下错误:
java.sql.SQLIntegrityConstraintViolationException: ORA-00001: unique constraint (ACTTRK.AIR_ID_PK) violated.**
我该如何解决这个问题?
设置当前序列值
alter sequence ITEMS_SEQ restart start with <your_max_value+1>;
如果这不起作用
ALTER SEQUENCE ITEMS_SEQ INCREMENT BY <your_max_value>;
select ITEMS_SEQ.nextval from dual;
ALTER SEQUENCE ITEMS_SEQ INCREMENT BY 1;
下面是我的 java 代码的一部分,我们用它来将记录插入 table。
public void insertitem(long item_id, long user_id) throws SQLException
{
PreparedStatement pstmt = null;
StringBuffer sqlB = new StringBuffer();
sqlB.append("INSERT INTO ITEMS ");
sqlB.append("(AIR_ID, ACT_ITEM_ID, USER_ID) ");
sqlB.append(" VALUES ");
sqlB.append("(ITEMS_SEQ.nextval,?,?) ");
try
{
pstmt = conn.prepareStatement(sqlB.toString());
int i=1;
pstmt.setLong(i, item_id);i++;
pstmt.setLong(i, user_id);i++;
pstmt.executeUpdate();
}
catch(SQLException e)
{
throw new SQLException(e.getMessage());
}
}
即使我使用 SEQ.nextval,它仍然会抛出以下错误:
java.sql.SQLIntegrityConstraintViolationException: ORA-00001: unique constraint (ACTTRK.AIR_ID_PK) violated.**
我该如何解决这个问题?
设置当前序列值
alter sequence ITEMS_SEQ restart start with <your_max_value+1>;
如果这不起作用
ALTER SEQUENCE ITEMS_SEQ INCREMENT BY <your_max_value>;
select ITEMS_SEQ.nextval from dual;
ALTER SEQUENCE ITEMS_SEQ INCREMENT BY 1;