Reputation: 127
below is some part of my java code which we are using to insert record into a 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());
}
}
even though iam using SEQ.nextval, it still throwing the below error:
java.sql.SQLIntegrityConstraintViolationException: ORA-00001: unique constraint (ACTTRK.AIR_ID_PK) violated.**
how can i resolve this ?
Upvotes: 0
Views: 1980
Reputation: 4914
Set the current sequence value with
alter sequence ITEMS_SEQ restart start with <your_max_value+1>;
If this doesn't work
ALTER SEQUENCE ITEMS_SEQ INCREMENT BY <your_max_value>;
select ITEMS_SEQ.nextval from dual;
ALTER SEQUENCE ITEMS_SEQ INCREMENT BY 1;
Upvotes: 1