<%@ 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(); } %>