简体   繁体   中英

java.sql.SQLIntegrityConstraintViolationException: ORA-00001

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?

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM