Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4ac96b4a7a | |||
| ca60cdc8a5 | |||
| 2a3a2e9497 | |||
| c25c4e2a46 | |||
| 5d6146e448 | |||
| f445f9dbca | |||
| 16bfe69c86 | |||
| 720ff7e502 |
Binary file not shown.
@@ -0,0 +1,9 @@
|
||||
-- Table principale : les rappels
|
||||
|
||||
CREATE TABLE rappel (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
titre VARCHAR(50) NOT NULL,
|
||||
contenu TEXT,
|
||||
theme VARCHAR(30),
|
||||
rang INT
|
||||
);
|
||||
@@ -0,0 +1,59 @@
|
||||
package fr.iutfbleau.papillon.controller;
|
||||
|
||||
import fr.iutfbleau.papillon.model.BaseDeDonnees;
|
||||
import fr.iutfbleau.papillon.model.Rappel;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GestionRappel {
|
||||
|
||||
public void ajouter(Rappel r) throws SQLException {
|
||||
String sql = "INSERT INTO rappel (titre, contenu, theme, rang) VALUES (?, ?, ?, ?)";
|
||||
Connection cnx = BaseDeDonnees.getConnexion();
|
||||
PreparedStatement pst = cnx.prepareStatement(sql);
|
||||
pst.setString(1, r.getTitre());
|
||||
pst.setString(2, r.getContenu());
|
||||
pst.setString(3, r.getTheme());
|
||||
pst.setInt(4, r.getRang());
|
||||
pst.executeUpdate();
|
||||
pst.close();
|
||||
}
|
||||
|
||||
public List<String> lister() throws SQLException {
|
||||
String sql = "SELECT id, titre, theme, rang FROM rappel ORDER BY id DESC";
|
||||
List<String> res = new ArrayList<>();
|
||||
Connection cnx = BaseDeDonnees.getConnexion();
|
||||
PreparedStatement pst = cnx.prepareStatement(sql);
|
||||
ResultSet rs = pst.executeQuery();
|
||||
while (rs.next()) {
|
||||
res.add(rs.getInt("id") + " | " + rs.getString("titre") + " | " + rs.getString("theme") + " | " + rs.getInt("rang"));
|
||||
}
|
||||
rs.close();
|
||||
pst.close();
|
||||
return res;
|
||||
}
|
||||
|
||||
public void supprimerParId(int id) throws SQLException {
|
||||
String sql = "DELETE FROM rappel WHERE id = ?";
|
||||
Connection cnx = BaseDeDonnees.getConnexion();
|
||||
PreparedStatement pst = cnx.prepareStatement(sql);
|
||||
pst.setInt(1, id);
|
||||
pst.executeUpdate();
|
||||
pst.close();
|
||||
}
|
||||
|
||||
public void modifierParId(int id, Rappel r) throws SQLException {
|
||||
String sql = "UPDATE rappel SET titre = ?, contenu = ?, theme = ?, rang = ? WHERE id = ?";
|
||||
Connection cnx = BaseDeDonnees.getConnexion();
|
||||
PreparedStatement pst = cnx.prepareStatement(sql);
|
||||
pst.setString(1, r.getTitre());
|
||||
pst.setString(2, r.getContenu());
|
||||
pst.setString(3, r.getTheme());
|
||||
pst.setInt(4, r.getRang());
|
||||
pst.setInt(5, id);
|
||||
pst.executeUpdate();
|
||||
pst.close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package fr.iutfbleau.papillon.model;
|
||||
import org.mariadb.jdbc.MariaDbDataSource;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class BaseDeDonnees {
|
||||
|
||||
private static Connection connexion;
|
||||
|
||||
public static Connection getConnexion() {
|
||||
if (connexion == null) {
|
||||
try {
|
||||
MariaDbDataSource dataSource = new MariaDbDataSource();
|
||||
dataSource.setUrl("jdbc:mariadb://localhost:3307/papillon");
|
||||
dataSource.setUser("root");
|
||||
dataSource.setPassword("mdp");
|
||||
|
||||
connexion = dataSource.getConnection();
|
||||
System.out.println(" Connexion réussie !");
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return connexion;
|
||||
}
|
||||
|
||||
public static void fermer() {
|
||||
try {
|
||||
if (connexion != null && !connexion.isClosed()) {
|
||||
connexion.close();
|
||||
System.out.println(" Connexion fermée.");
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package fr.iutfbleau.papillon.model;
|
||||
|
||||
public class Rappel {
|
||||
private int id;
|
||||
private String titre;
|
||||
private String contenu;
|
||||
private LocalDateTime date;
|
||||
|
||||
public Rappel(int id, String titre, String contenu, LocalDateTime date) {
|
||||
this.id = id;
|
||||
this.titre = titre;
|
||||
this.contenu = contenu;
|
||||
this.date = date;
|
||||
}
|
||||
public Rappel(String titre, String contenu, String theme, int rang){
|
||||
this(0,titre,contenu,theme,rang);
|
||||
}
|
||||
|
||||
public int getId(){
|
||||
return id;
|
||||
}
|
||||
public String getTitre(){
|
||||
return titre;
|
||||
}
|
||||
public String getContenu(){
|
||||
return contenu;
|
||||
}
|
||||
public String getTheme(){
|
||||
return theme;
|
||||
}
|
||||
public int getRang(){
|
||||
return rang;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user