Commit f9e0f3a8 authored by Clara Stoddart's avatar Clara Stoddart

Changed database population to write into localhost mysql database instead of...

Changed database population to write into localhost mysql database instead of Heroku database, fixed bug in php file
parent f929d057
<component name="libraryTable">
<library name="mysql-connector-java-5.1.49">
<CLASSES>
<root url="jar://C:/mysql-connector-java-5.1.49/mysql-connector-java-5.1.49.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>
\ No newline at end of file
......@@ -8,5 +8,6 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="postgresql-42.2.14" level="project" />
<orderEntry type="library" name="mysql-connector-java-5.1.49" level="project" />
</component>
</module>
\ No newline at end of file
......@@ -15,7 +15,7 @@ import java.util.*;
*/
public class CSVReading {
private static String csvFile = "C:\\Clickerance\\chrome-groceries-extension\\database-creation\\src\\25-June-2020-data.csv";
private static String csvFile = "C:\\Clickerance\\chrome-groceries-extension\\webscraping\\25-June-2020-data.csv";
private static final String TABLE_NAME = "ProductsIngredients";
enum Ingredient {
......@@ -33,8 +33,8 @@ public class CSVReading {
*/
public static void main(String[] args) {
DatabaseConnection connection = new DatabaseConnection(TABLE_NAME);
connection.deleteTable();
connection.createTable();
//connection.deleteTable();
//connection.createTable();
BufferedReader csvReader;
try {
csvReader = new BufferedReader(new FileReader(csvFile));
......@@ -67,7 +67,8 @@ public class CSVReading {
*/
String[] row = line.split(",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)");
Map<Ingredient, Boolean> contains = parseIngredients(row[ingredientsIndex]);
Map<Ingredient, Boolean> mayContain = parseAllergens(row[allergensIndex]);
Map<Ingredient, Boolean> mayContain = new HashMap<>();
// mayContain = parseAllergens(row[allergensIndex]);
writeProduct(row[nameIndex], contains, mayContain, connection);
}
} catch (IOException e) {
......
......@@ -51,11 +51,14 @@ public class DatabaseConnection {
}
private static java.sql.Connection getConnection() throws URISyntaxException, SQLException {
URI dbUri = new URI(System.getenv("DATABASE_URL"));
String username = dbUri.getUserInfo().split(":")[0];
String password = dbUri.getUserInfo().split(":")[1];
String dbUrl = "jdbc:postgresql://" + dbUri.getHost() + dbUri.getPath();
return DriverManager.getConnection(dbUrl, username, password);
// Heroku database connection: (Uses postgresql jdbc driver)
// URI dbUri = new URI(System.getenv("DATABASE_URL"));
// String username = dbUri.getUserInfo().split(":")[0];
// String password = dbUri.getUserInfo().split(":")[1];
// String dbUrl = "jdbc:postgresql://" + dbUri.getHost() + dbUri.getPath();
// return DriverManager.getConnection(dbUrl, username, password);
// Local host phpmyadmin database
return DriverManager.getConnection("jdbc:mysql://localhost/public", "root", "");
}
}
......
......@@ -17,7 +17,7 @@ $result = $stmt->fetch();
if ($result == false) {
echo "8";
} else {
if (!(($containsdairy & (1 & $dietNum)) | ($containsmeat & (2 & $dietNum)) | ($containscorn & (4 & $dietNum)) | ($containsgluten & (8 & $dietNum)))) {
if (!(($containsdairy & boolval(1 & $dietNum)) | ($containsmeat & boolval(2 & $dietNum)) | ($containscorn & boolval(4 & $dietNum)) | ($containsgluten & boolval(8 & $dietNum)))) {
echo "1";
} else {
echo "0";
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment