I have a problem, I don't know how to SELECT columns FROM table in database WHERE datetime is some particular date.
I do like this:
public List<Dezurstvo> vratiPredmeteISatnicuPocetkaIspita(Dezurstvo dezurstvo) throws SQLException, ParseException{
SimpleDateFormat ulazniformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String ulaz = ulazniformat.format(dezurstvo.getDatum());
Date izlaz = new Date(ulazniformat.parse(ulaz).getTime());
String sqlVratiPredmeteISatnicuPocetkaIspita = "SELECT PredmetID, Datum FROM dezurstvo WHERE (NastavnikID = " + dezurstvo.getNastavnik().getNastavnikId() +") AND (Datum = " + izlaz + ")";
Statement stat = konekcija.createStatement();
ResultSet rs = stat.executeQuery(sqlVratiPredmeteISatnicuPocetkaIspita);
List<Dezurstvo> listaDezurstava = new ArrayList();
while(rs.next()){
.............etc.
There is some code after that, but the problem is, there isn't error, but this rs.next() is empty, this ResultSet rs is actually empty, it doesn't find rows that matches whit this date, even thaw I insert date that exist in database in form from which I get date. It just doesn't do this while loop, it jumps over it, because I suppose rs is empty.
Probably the problem is because I don't know how to compare this two date. In my mySql database datetime format is this yyyy-MM-dd HH:mm:ss, so I tried to change format of date red from form to this database format because I thought this is the problem. But still doesn't work...
Now I think the problem is maybe this Date izlaz = new Date... is sql.Date and maybe it only contains yyyy-MM-dd but not HH:mm:ss...And it can`t compair...
Please help, I`m struggling with this for few days...
And this is different question from "Date Java to MySql DateTime" which somebody told it is duplicate, because I am not sure what is the reason why my code doesn`t work...