From 61e9b4df54919c5366065e1ae7a8fbf08216b733 Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Thu, 25 Apr 2019 07:00:50 +0200 Subject: [PATCH] ~weird bug fixed: head->desk Signed-off-by: Johannes Theiner --- src/main/java/de/hsel/itech/db/Database.java | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) 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(); }