From 07fa6d09a40e09c6d2cbb3680c4920a1222393df Mon Sep 17 00:00:00 2001 From: Julian Hinxlage Date: Tue, 16 Apr 2019 16:06:26 +0200 Subject: [PATCH] fixed database creation --- src/main/java/de/hsel/itech/db/Database.java | 1 + src/main/resources/database.sql | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/hsel/itech/db/Database.java b/src/main/java/de/hsel/itech/db/Database.java index 3b9267e..82c8e0c 100644 --- a/src/main/java/de/hsel/itech/db/Database.java +++ b/src/main/java/de/hsel/itech/db/Database.java @@ -43,6 +43,7 @@ public class Database { assert connection != null; try(BufferedReader br = new BufferedReader(new FileReader(getClass().getClassLoader().getResource("database.sql").getFile()))) { for (String line = br.readLine(); line != null; line = br.readLine()) { + System.out.println(line); PreparedStatement statement = connection.prepareStatement(line); statement.executeUpdate(); statement.close(); diff --git a/src/main/resources/database.sql b/src/main/resources/database.sql index 34fe222..61bd410 100644 --- a/src/main/resources/database.sql +++ b/src/main/resources/database.sql @@ -1,6 +1,6 @@ -CREATE TABLE IF NOT EXISTS test(id bigint, primary key auto_increment, hello varchar(25)); +CREATE TABLE IF NOT EXISTS test(id bigint primary key auto_increment, hello varchar(25)); INSERT IGNORE INTO test(hello) values ('Welt'); -CREATE TABLE IF NOT EXISTS book (id bigint primary key auto_increment, title varchar(50), description varchar(500) unique , price int, year year, publisher bigint, category bigint, image varchar(11) unique); +CREATE TABLE IF NOT EXISTS book (id bigint primary key auto_increment, title varchar(50), description varchar(500), price int, year year, publisher bigint, category bigint, image varchar(11) unique); CREATE TABLE IF NOT EXISTS publisher(id bigint primary key auto_increment, name varchar(50) unique); CREATE TABLE IF NOT EXISTS author(id bigint primary key auto_increment, name varchar(50) unique); CREATE TABLE IF NOT EXISTS author_book(author bigint, book bigint, primary key(author, book), foreign key (author) REFERENCES author(id), foreign key (book) references book(id));