I have this code that works very well, it receives input parameters from a DOM and sends them through ajax to an endpoint that sends them to the DB at the same time. the theme comes here, I want to validate two dates, one for planes and one for arrival, however the parameters that are in the setString () are clearly String, which I do not think I can validate them.
I put those input as String since the input html5 gives me a format type String "yyyy-MM-dd", which is the same format that the Date column of Mysql receives. (The insert works very well but now I want to validate) How can I build that String that I receive from an HTML and be able to validate it beforehand to the database?
My idea is to do a static class, however I am overwhelmed by the amount of classes related to the dates that I have and I do not know how to do it, one fact is that I am using java 8 and several methods of the Date class do not allows them to use "deprecated".
I leave parts of code.
endpoint:
PreparedStatement ps;
String sql="INSERT INTO vuelos(id_avion, id_administrador, empresa, destino, escalas, pasajes, fechaSalida, horarioSalida, fechaArribo, horarioArribo, pago, precio) values(?,?,?,?,?,?,?,?,?,?,?,?)";
ps= con.prepareStatement(sql);
ps.setInt(1, id_avion);
ps.setInt(2, int_id_usuarioAdmin);
ps.setString(3, empresa);
ps.setString(4, destino);
ps.setInt(5, escalas);
ps.setInt(6, pasajes);
ps.setString(7, fechaSalida); //validar
ps.setString(8, horarioSalida);//validar
ps.setString(9, fechaArribo);
ps.setString(10, horarioArribo);
ps.setString(11, pago);
ps.setInt(12, precio);
ps.executeUpdate();
ps.close();
listado.add(new Vuelo(0,empresa,destino, escalas, pasajes, fechaSalida, horarioSalida,fechaArribo, horarioArribo, pago, precio));
str_toJson= gson.toJson(listado);
return str_toJson;
}
Part of the html:
<tr>
<td>
<input id="fechaSalida" type="date">
</td>
<td>
<input id="horarioSalida" type="time" name="horarioSalida">
</td>
</tr>
<tr>
<td>
<label name="fechaArribo">Fecha de arribo:</label>
</td>
<td>
<label name="HorarioArribo">Horario de arribo:</label>
</td>
</tr>
<tr>
<td>
<input id="fechaArribo" type="date">
</td>
<td>
<input id="horarioArribo" type="time" name="horarioArribo">
</td>
</tr>