Dates

Mya
1,700 views

Open Source Your Knowledge, Become a Contributor

Technology knowledge has to be shared and made accessible for free. Join the movement.

Create Content

Welcome!

This Java template lets you get started quickly with a simple one-page playground.

package com.lecko.servlets;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Hashtable;
import java.sql.Connection;
import java.sql.Date;
import java.sql.ResultSet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class GestionDates extends HttpServlet {
public class Tuple<X, Y> {
public final X x;
public final Y y;
public Tuple(X x, Y y) {
this.x = x;
this.y = y;
}
}
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
res.setContentType("text/html");
PrintWriter pw = res.getWriter();
Connection con = null;
Statement st=null;
try {
// Load JDBC driver "com.mysql.jdbc.Driver"
Class.forName("com.mysql.jdbc.Driver").newInstance();
/* create a connection to the database by using Connection interface
and java.sql.DriverManager's getConnection( ) method */
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/lecko","java2","Testtest2!");
st = con.createStatement();
ResultSet rs = st.executeQuery("SELECT idindicateur, min(date), max(date) FROM indicateur_community GROUP BY idindicateur;");
var tupledate = new Tuple<Date, Date>(rs.getDate(2), rs.getDate(3));
Hashtable<Integer, Tuple<Date, Date>> h = new Hashtable<Integer, Tuple<Date, Date>>();
h.put(rs.getInt(1), tupledate);
pw.println("<!DOCTYPE html>");
pw.println("<html>");
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Advanced usage

If you want a more complex example (external libraries, viewers...), use the Advanced Java template

Open Source Your Knowledge: become a Contributor and help others learn. Create New Content