Dates
Mya
2,793 views
Open Source Your Knowledge, Become a Contributor
Technology knowledge has to be shared and made accessible for free. Join the movement.
Welcome!
This Java template lets you get started quickly with a simple one-page playground.
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
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);
Press desired key combination and then press ENTER.
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