Skip to content
Advertisement

jdbc. preparedStatement incrementing value in sql

I have 2 tables in database authors (author_id, first_name, last_name); books (book_id, book_title, book_author_id); book_author_id is fk to author_id

and when im trying to fill database for tests

receiving this log

as you can see preparedStatement increment book_author_id by 1 each time when im saving book into database, but it shouldn’t do this. can you please explain why this happening and how to fix this. if i will use just database console sql queries it will work, but if using prepared statement got this problem. Added book dao save method

isExists same method with select * from books where book_title = ‘title’ and book_author_id = id return true if exists and false if doesnt

Advertisement

Answer

when you look at your code sample: you’re setting the second parameter of your prepared statement to the book id, instead of the book_author_id.

Your code:

but it should be

as a matter of fact- the ID of the books is incrementing by one for each

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement