Commit | Line | Data |
---|---|---|
d2793705 JB |
1 | <%@ page import="java.io.*, java.util.*, javax.servlet.*, java.sql.*" %> |
2 | <%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> | |
3 | ||
4 | <meta charset="UTF-8"> | |
5 | <html> | |
6 | <body> | |
7 | ||
8 | <h1>Liste des livres</h1> | |
9 | ||
10 | <% | |
11 | ||
12 | Connection connection = null; | |
13 | Statement stmt = null; | |
14 | try { | |
15 | String connectionURL = "jdbc:mysql://localhost/MyBd?useUnicode=yes&characterEncoding=UTF-8"; | |
16 | Class.forName("com.mysql.jdbc.Driver").newInstance(); | |
17 | connection = DriverManager.getConnection(connectionURL, "MyBd", "MyBd"); | |
18 | if(!connection.isClosed()) { | |
19 | String query = "SELECT nom_livre, auteur FROM details_livres"; | |
20 | stmt = connection.createStatement(); | |
21 | ResultSet rs = stmt.executeQuery(query); | |
22 | while (rs.next()) { | |
23 | String title = rs.getString("nom_livre"); | |
24 | String author = rs.getString("auteur"); | |
25 | //TODO: make a html table | |
26 | out.println(title + " par " + author + "<br>"); | |
27 | } | |
28 | } | |
29 | } catch (Exception e){ | |
30 | out.println("Unable to connect to database or run query: " + e); | |
31 | } | |
32 | finally { | |
33 | if (connection != null) | |
34 | connection.close(); | |
35 | if (stmt != null) | |
36 | stmt.close(); | |
37 | } | |
38 | ||
39 | %> | |
40 | ||
41 | </body> | |
42 | </html> |