I have a database created with phpMyAdmin, and in a "reservations" table I have a field that asks me for the specific date and time of a reservation. Now the problem is in which at the time of inserting the reservation, I do not take the date, when I do and I get an error:
PreparedStatement ps = conn.prepareStatement("INSERT INTO reserva (nombre, dni, fecha, id_mesa, vigente) VALUES (?, ?, ?, ?, 1)", Statement.RETURN_GENERATED_KEYS);
LocalDateTime ldt = reserva.getFecha();
ps.setDate(3, ldt);
He does not let me set it up like this
PreparedStatement ps = conn.prepareStatement("INSERT INTO reserva (nombre, dni, fecha, id_mesa, vigente) VALUES (?, ?, ?, ?, 1)", Statement.RETURN_GENERATED_KEYS);
LocalDateTime ldt = reserva.getFecha();
ps.setString(3, ldt.getYear()+"-"+ldt.getDayOfMonth()+"-"+ldt.getDayOfMonth()+" "+ldt.getHour()+":"+ldt.getMinute()+":00");
With the rest of the data is perfect, how can I make a specific date with the database?
Greetings and thanks.