添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
火星上的猴子  ·  java - Bouncy Castle ...·  2 年前    · 
追风的便当  ·  Java IO ...·  2 年前    · 
重感情的生姜  ·  .net - C# Process ...·  2 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I have created a database with the name of Sequence in Java.

stmt = dbConn.createStatement();
sql = "CREATE TABLE IF NOT EXISTS Sequence(Seq_Num TEXT Primary Key not null, Seq_ID TEXT, "
       + E_ID TEXT," + "FOREIGN KEY(E_ID) REFERENCES Emitter(E_ID))";
stmt.executeUpdate(sql);

Now clearly I have not labeled the column Seq_ID as UNIQUE.

So when I execute the following statement:

sql = "INSERT INTO Sequence(Seq_Num, Seq_ID, E_ID) VALUES('" + value + "','" + model.txtSaveAs.getText() 
         + "','" + model.namesList.get(i) + "')";
stmt.execute(sql);

It is giving me this error:

java.sql.SQLException: [SQLITE_CONSTRAINT]  Abort due to constraint violation (column Seq_ID is not unique)

How do I solve this problem?

The problem was that the table initially contained 4 columns but i had edited the create table statement. But as the table already existed so the changes were never implemented in the table. So I first deleted the table by the statement:

DROP TABLE Sequence

And then created the table again; this time with 3 columns.

That is what I said initially :) Either with sequence_id or not, 2nd column was being taken as sequence – Optional Sep 28, 2017 at 5:10

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.