X-Git-Url: https://git.piment-noir.org/?p=TD_webapps.git;a=blobdiff_plain;f=ROOT%2Fexo9%2Fviewbooks.jsp;fp=ROOT%2Fexo9%2Fviewbooks.jsp;h=02b2591ca0395c055e2b07e6197cb241a25371c6;hp=0000000000000000000000000000000000000000;hb=d2793705bda98fb61daa7811d9607f5002c2595e;hpb=714e1b9156a383581be324ae0792e6e0767a7106 diff --git a/ROOT/exo9/viewbooks.jsp b/ROOT/exo9/viewbooks.jsp new file mode 100644 index 0000000..02b2591 --- /dev/null +++ b/ROOT/exo9/viewbooks.jsp @@ -0,0 +1,42 @@ +<%@ page import="java.io.*, java.util.*, javax.servlet.*, java.sql.*" %> +<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> + + + + + +

Liste des livres

+ +<% + +Connection connection = null; +Statement 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()) { + String query = "SELECT nom_livre, auteur FROM details_livres"; + stmt = connection.createStatement(); + ResultSet rs = stmt.executeQuery(query); + while (rs.next()) { + String title = rs.getString("nom_livre"); + String author = rs.getString("auteur"); + //TODO: make a html table + out.println(title + " par " + author + "
"); + } + } + } 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