1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
Connection connexion = null;
resp.setContentType("text/html");
PrintWriter out = resp.getWriter();
out.println("<html>");
out.println("<body>");
out.println("<table>");
try {
Class.forName("com.mysql.jdbc.Driver");
connexion = DriverManager.getConnection("jdbc:mysql://192.168.0.176:3306/physique","anthony","bidule");
Statement instruction = connexion.createStatement();
ResultSet resultat = instruction.executeQuery("SELECT * FROM tblUtilisateur");
if(resultat.next()){
out.println("<tr><td>pas de résultat</td></tr>");
}
while(resultat.next()){
out.println("<tr>");
out.println("<td>"+resultat.getString("IdUtil")+"</td>");
out.println("<td>"+resultat.getString("Nom")+"</td>");
out.println("<td"+resultat.getString("Prenom")+"</td>");
out.println("</tr>");
}
}
catch (Exception e) {
System.out.println("echec pilote : "+e);
}
finally {
if (connexion != null) {
try {
connexion.close();
}
catch (SQLException e) {
e.printStackTrace();
}
}
}
out.println("</table>");
} |
Partager