X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=inline;f=ROOT%2Fexo9%2Faddbook.jsp;fp=ROOT%2Fexo9%2Faddbook.jsp;h=a0fb03579a91ce6b8b9dd0742c8954e6c2650bb1;hb=d2793705bda98fb61daa7811d9607f5002c2595e;hp=0000000000000000000000000000000000000000;hpb=714e1b9156a383581be324ae0792e6e0767a7106;p=TD_webapps.git
diff --git a/ROOT/exo9/addbook.jsp b/ROOT/exo9/addbook.jsp
new file mode 100644
index 0000000..a0fb035
--- /dev/null
+++ b/ROOT/exo9/addbook.jsp
@@ -0,0 +1,52 @@
+<%@ page import="java.io.*, java.util.*, javax.servlet.*, java.sql.*" %>
+<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
+
+
+
+
+
+Ajouter un livre
+
+
+<%
+request.setCharacterEncoding("UTF-8");
+String isNew = request.getParameter("new");
+
+if (isNew != null && isNew.equals("true")) {
+ String title = request.getParameter("title");
+ String author = request.getParameter("author");
+ Connection connection = null;
+ PreparedStatement stmt = null;
+ try {
+ String connectionURL = "jdbc:mysql://localhost/MyBd?useUnicode=yes&characterEncoding=UTF-8";
+ Class.forName("com.mysql.jdbc.Driver").newInstance();
+ connection = DriverManager.getConnection(connectionURL, "MyBd", "MyBd");
+ if(!connection.isClosed()) {
+ stmt = connection.prepareStatement("INSERT INTO details_livres (nom_livre, auteur) VALUES (?, ?)");
+ stmt.setString(1, title);
+ stmt.setString(2, author);
+ stmt.executeUpdate();
+ out.println("Book " + title + " by " + author + " successfully added");
+ }
+ } catch (Exception e){
+ out.println("Unable to connect to database or run query: " + e);
+ }
+ finally {
+ if (connection != null)
+ connection.close();
+ if (stmt != null)
+ stmt.close();
+ }
+
+}
+
+%>
+
+
+
\ No newline at end of file