diff --git a/init.sql b/init.sql index 159df45..6fc8c40 100644 --- a/init.sql +++ b/init.sql @@ -17,7 +17,7 @@ CREATE TABLE IF NOT EXISTS publisher VARCHAR(255), originalprice DECIMAL(10, 2), discountedprice DECIMAL(10, 2), - href VARCHAR(255) + url VARCHAR(255) ); INSERT INTO diff --git a/src/server/tools/crawling/Book.java b/src/server/tools/crawling/Book.java index 56e5f5f..49ff289 100644 --- a/src/server/tools/crawling/Book.java +++ b/src/server/tools/crawling/Book.java @@ -6,19 +6,19 @@ public class Book { private String publisher; private double originalprice; private double discountedprice; - private String href; + private String url; public Book() { } public Book(String title, String author, String publisher, double originalprice, double discountedprice, - String href) { + String url) { this.title = title; this.author = author; this.publisher = publisher; this.originalprice = originalprice; this.discountedprice = discountedprice; - this.href = href; + this.url = url; } public String getTitle() { @@ -61,18 +61,18 @@ public class Book { this.discountedprice = discountedprice; } - public String getHref() { - return href; + public String getUrl() { + return url; } - public void setHref(String href) { - this.href = href; + public void setUrl(String url) { + this.url = url; } @Override public String toString() { return "Title: " + this.title + ", Author: " + this.author + ", Publisher: " + this.publisher + ", Original Price: " + this.originalprice + ", Discounted Price: " + this.discountedprice + ", URL: " - + this.href; + + this.url; } } diff --git a/src/server/tools/crawling/NewsThread.java b/src/server/tools/crawling/NewsThread.java index 131cf15..0021518 100644 --- a/src/server/tools/crawling/NewsThread.java +++ b/src/server/tools/crawling/NewsThread.java @@ -36,10 +36,10 @@ public class NewsThread implements Runnable { : null; String oprice = bookElement.select(".price_r").text(); String nprice = bookElement.select(".price_n").first().text(); - String href = bookElement.select(".name a").attr("href"); + String url = bookElement.select(".name a").attr("href"); double originalprice = Double.parseDouble(oprice.substring(1)); double discountedprice = Double.parseDouble(nprice.substring(1)); - insertBook(con, title, author, publisher, originalprice, discountedprice, href); + insertBook(con, title, author, publisher, originalprice, discountedprice, url); } } catch (SQLException e) { e.printStackTrace(); @@ -50,7 +50,7 @@ public class NewsThread implements Runnable { } private void insertBook(Connection con, String title, String author, String publisher, double originalprice, - double discountedprice, String href) throws SQLException { + double discountedprice, String url) throws SQLException { String sql = "INSERT INTO book VALUES (?, ?, ?, ?, ?, ?)"; try (PreparedStatement ps = con.prepareStatement(sql)) { ps.setString(1, title); @@ -58,7 +58,7 @@ public class NewsThread implements Runnable { ps.setString(3, publisher); ps.setDouble(4, originalprice); ps.setDouble(5, discountedprice); - ps.setString(6, href); + ps.setString(6, url); ps.executeUpdate(); } }