Skip to content
Snippets Groups Projects
Commit 95f1407a authored by Gwendal Margely's avatar Gwendal Margely :alembic:
Browse files

ajout doc et modif IngredientDAO.java

parent 127dfc41
No related branches found
No related tags found
No related merge requests found
# 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 = ?;
```
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);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment