diff --git a/Documentation/documentation.md b/Documentation/documentation.md new file mode 100644 index 0000000000000000000000000000000000000000..ce410cc8d337f554c893ec7aff4575378fbe4c6b --- /dev/null +++ b/Documentation/documentation.md @@ -0,0 +1,27 @@ +# Documentation pour les tables et les requetes + +## Table Ingrédients + +### Création de la table + +```sql +/*au cas ou l'on voudrait être un terroriste et enlever la table si elle existe déja DROP TABLE IF EXISTS ingredients CASCADE;*/ +CREATE TABLE ingredients(id INT PRIMARY KEY, nom TEXT UNIQUE, price REAL); +INSERT INTO TABLE ingredients(id,nom ,price) VALUES (1,'jambon',2.00),(2,'poivrons',3.00),(3,'mozarella',2.50),(4,'lardons',2.20),(5,'miel',3.50),(6,'chorizo',4.00); +``` + +### Requête sur la table + +FIND ALL +```sql +SELECT nom ,price FROM ingredients; +``` + +Sélectionner seulement un ingrédient \ +les ? représentent l'élément passé en argument + +```sql +SELECT nom , price , FROM ingrédient where id = ?; +``` + + diff --git a/WEB-INF/src/DAO/IngredientDAO.java b/WEB-INF/src/DAO/IngredientDAO.java index ba48122ae837e36dbf72e82ddc9c304fb4871cb0..5eec7f82f479cb809173302107e1a6eed4874911 100644 --- a/WEB-INF/src/DAO/IngredientDAO.java +++ b/WEB-INF/src/DAO/IngredientDAO.java @@ -1,4 +1,5 @@ package DAO; + import Exceptions.IngredientDAOException; import POJO.Ingredient; @@ -19,8 +20,8 @@ public class IngredientDAO { // SQL queries private static final String SELECT_ALL_QUERY = "SELECT * FROM ingredients"; - private static final String INSERT_QUERY = "INSERT INTO ingredients(name, price) VALUES (?, ?)"; - private static final String SELECT_BY_ID_QUERY = "SELECT * FROM ingredients WHERE id = ?"; + private static final String INSERT_QUERY = "INSERT INTO ingredients(nom, price) VALUES (?, ?)"; + private static final String SELECT_BY_ID_QUERY = "SELECT nom,price FROM ingredients WHERE id = ?"; private static final String DELETE_QUERY = "DELETE FROM ingredients WHERE id = ?"; // Method to establish database connection @@ -60,7 +61,7 @@ public class IngredientDAO { while (resultSet.next()) { int id = resultSet.getInt("id"); - String name = resultSet.getString("name"); + String name = resultSet.getString("nom"); double price = resultSet.getDouble("price"); Ingredient ingredient = new Ingredient(id, name, price); ingredients.add(ingredient); @@ -99,7 +100,7 @@ public class IngredientDAO { resultSet = preparedStatement.executeQuery(); if (resultSet.next()) { - String name = resultSet.getString("name"); + String name = resultSet.getString("nom"); double price = resultSet.getDouble("price"); ingredient = new Ingredient(id, name, price); }