error while using a database in java using sqlite

The obvious errors in your code in update() method are the comma after SET Balance = ? which you must remove and also change the indices of stmt.setInt() to 1 for balance and 2 for accountNo because you are passing 2 paremeters with that order in your UPDATE statement:

String change = "UPDATE accounts SET Balance = ? WHERE AccountNumber = ?";
try {
    PreparedStatement stmt = conn.prepareStatement(change);

Also, the error message:

Abort due to constraint violation (UNIQUE constraint failed: accounts.AccountNumber)

means that you are trying to insert in the table an account number that already exists in the table and this is not allowed because the column AccountNumber is the primary key of the table so it is unique.

Also, inside createTable() what is sc? Is it a resultset?
If so, what are you trying to do? Are you trying to loop through the rows of the table?
The table is just created and it is empty.

From the code that you posted, I can’t see why you get 4 times the message “A new database has been created”, because I don’t know how you call the method createTable().

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top