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.
–
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.