From a11d922a0e5e8854e87cff00d40c2044a202c93c Mon Sep 17 00:00:00 2001 From: Jim Martens Date: Wed, 28 Jun 2017 16:49:29 +0200 Subject: [PATCH] Added methods to add dimension data Signed-off-by: Jim Martens --- 07/src/de/dis2017/data/db/ORM.java | 61 ++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/07/src/de/dis2017/data/db/ORM.java b/07/src/de/dis2017/data/db/ORM.java index dae4690..76cd6fa 100644 --- a/07/src/de/dis2017/data/db/ORM.java +++ b/07/src/de/dis2017/data/db/ORM.java @@ -1,6 +1,7 @@ package de.dis2017.data.db; import de.dis2017.data.Article; +import de.dis2017.data.Date; import de.dis2017.data.Shop; import java.sql.Connection; @@ -86,4 +87,64 @@ public class ORM { return shops; } + + public void createArticles(List
articles) { + String insertSQL = "INSERT INTO VSISP12.ARTICLE (ID, name, productgroup, productfamily, productcategory)" + + "VALUES (?, ?, ?, ?, ?)"; + try { + PreparedStatement pstmt = _connection.prepareStatement(insertSQL); + + for (Article article : articles) { + pstmt.setInt(1, article.get_articleID()); + pstmt.setString(2, article.get_name()); + pstmt.setString(3, article.get_productGroup()); + pstmt.setString(4, article.get_productFamily()); + pstmt.setString(5, article.get_productCategory()); + pstmt.addBatch(); + } + pstmt.executeBatch(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + public void createShops(List shops) { + String insertSQL = "INSERT INTO VSISP12.SHOP (ID, name, city, region, country)" + + "VALUES (?, ?, ?, ?, ?)"; + try { + PreparedStatement pstmt = _connection.prepareStatement(insertSQL); + + for (Shop shop : shops) { + pstmt.setInt(1, shop.get_shopID()); + pstmt.setString(2, shop.get_name()); + pstmt.setString(3, shop.get_city()); + pstmt.setString(4, shop.get_region()); + pstmt.setString(5, shop.get_country()); + pstmt.addBatch(); + } + pstmt.executeBatch(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + public void createDates(List dates) { + String insertSQL = "INSERT INTO VSISP12.DATETABLE (ID, day, month, quarter, year)" + + "VALUES (?, ?, ?, ?, ?)"; + try { + PreparedStatement pstmt = _connection.prepareStatement(insertSQL); + + for (Date date : dates) { + pstmt.setInt(1, date.get_dateID()); + pstmt.setInt(2, date.get_day()); + pstmt.setInt(3, date.get_month()); + pstmt.setInt(4, date.get_quarter()); + pstmt.setInt(5, date.get_year()); + pstmt.addBatch(); + } + pstmt.executeBatch(); + } catch (SQLException e) { + e.printStackTrace(); + } + } }