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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*
* @author j.balaramane
*/
public class Tmensuelle extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
PrintWriter out = response.getWriter();
Connection cnx = null;
Statement st= null;
try {
String dateDeb = request.getParameter("dateDebut");
String dateFin = request.getParameter("dateFin");
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost/solar";
cnx=DriverManager.getConnection(url,"root","");
st=cnx.createStatement();
ResultSet rs= st.executeQuery("select date,heure,tension," +
"intensite,puissance from solaire where date between '"+dateDeb+"' and '"+dateFin+"'");
out.println("<html>");
out.println("<head>");
out.println("<title>Affichage de la base de données solaire</title>");
out.println("</head>");
out.println("<body><center>");
out.println("<table border='3'>");
out.println("<h1><center>Base de Données Solaire</center></h1>");
out.println("<th>Date</th><th>Heure</th>" +
"<th>Tension</th><th>Intensité</th><th>Puissance</th>");
while(rs.next() ){
String bddate= rs.getString("date");
String bdheure= rs.getString("heure");
String bdtension= rs.getString("tension");
String bdintensite= rs.getString("intensite");
String bdpuissance= rs.getString("puissance");
out.println("<tr>");
out.println("<td>"+bddate+"</td><td>"+bdheure+
"</td><td>"+bdtension+"</td><td>"+bdintensite+"</td>" +
"<td>"+bdpuissance+"</td>");
out.println("</tr>");
}
out.println("</tr>");
out.println("</table>");
out.println("</body>");
out.println("</html>");
// javax.swing.JOptionPane.showMessageDialog(null,"élèment charger");
}
catch(ClassNotFoundException e)
{
javax.swing.JOptionPane.showMessageDialog(null,"Probleme de driver ");
out.println(e.getMessage());
}
catch(SQLException e)
{
out.println(e.getMessage());
}
//instrucion executée dans tous les cas,qu'il y ait une exception ou pas
{
//fermeture du testment
if(st!= null)
{
try
{
st.close();
}
catch(SQLException e1){
e1.printStackTrace();
}
}
}
//fermeture de la connexion à la base de donées
if(cnx!=null)
{
try
{
cnx.close();
}
catch(SQLException e1)
{
e1.printStackTrace();
}
}
}
} |
Partager