fixed database creation

This commit is contained in:
Julian Hinxlage 2019-04-16 16:06:26 +02:00
parent 388459b6a2
commit 07fa6d09a4
2 changed files with 3 additions and 2 deletions

View File

@ -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();

View File

@ -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));