Professional Documents
Culture Documents
Method e
Method e
Method e
function deleteArticle(articleId) {
$.ajax({
url: "/articles/" + articleId,
type: "DELETE",
success: function (response) {
Swal.fire("Deleted!", response.message,
response.status).then(() => {
window.location.reload(); // Recharger la page pour mettre
à jour l'affichage
});
},
error: function () {
Swal.fire("Oops...", "Something went wrong with ajax!",
"error");
}
});
}
</script>
public void deleteArticle(int articleId) {
String dburl = "jdbc:mysql://localhost:3306/Articles_Stock";
String dbusername = "root";
String dbpassword = "";
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(dburl, dbusername,
dbpassword);
PreparedStatement pstmt = null;
pstmt = con.prepareStatement("DELETE FROM Articles_Stock WHERE id=?");
pstmt.setInt(1, articleId);
int i = pstmt.executeUpdate();
Articles_Stock obj = new Articles_Stock();
if (i != 0) {
obj.setStatus("success");
obj.setMessage("Article Delete Successfully");
} else {
obj.setStatus("error");
obj.setMessage("Unable to delete article....");
}
con.close();
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
}