diff --git a/src/main/java/de/hsel/itech/db/Database.java b/src/main/java/de/hsel/itech/db/Database.java index 0e7bea2..146d2a6 100644 --- a/src/main/java/de/hsel/itech/db/Database.java +++ b/src/main/java/de/hsel/itech/db/Database.java @@ -448,7 +448,7 @@ public class Database { assert category != null; try { - PreparedStatement statement = connection.prepareStatement("INSERT INTO " + book + "(isbn, title, description, " + + PreparedStatement statement = connection.prepareStatement("INSERT INTO book(isbn, title, description, " + "price, year, publisher, category, image) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS); statement.setLong(1, book.getIsbn()); statement.setString(2, book.getTitle()); @@ -466,15 +466,9 @@ public class Database { } for (Author author : authors) { - //FIXME: Prepared Statement is broken, parameters are null, but they are not - String query = "INSERT INTO " + authorBook + " (author, book) VALUES (?, ?);"; - String workingQuery = "INSERT INTO " + authorBook + " (author, book) VALUES (" + author.getId() + ", "+ lastId + ")"; - PreparedStatement authorStatement = connection.prepareStatement(workingQuery); - //statement.setLong(1, author.getId()); - //statement.setLong(2, lastId); - System.out.println(authorStatement); - System.out.println(author.getId()); - System.out.println(lastId); + PreparedStatement authorStatement = connection.prepareStatement("INSERT INTO " + authorBook + " (author, book) VALUES (?, ?);"); + authorStatement.setLong(1, author.getId()); + authorStatement.setLong(2, lastId); insertCount += authorStatement.executeUpdate(); }