I found some problem in compare two data types Variable -> java.sql.Date type.
Firstly i'm createing current data (yyyy-mm-dd):
java.util.Date date = new java.util.Date();
java.sql.Date dateSql = new Date(date.getTime());
Secoundly, im receiving data from MySQL:
MyDataEntity myDataEntity = session.getNamedQuery(MyDataEntity.GET_ELEMENT).uniqueResult();
Then i'm trying to compare two dates:
if(dataSql != myDataEntity.getDate()){
System.out.println("different");
}else{
System.out.println("these same");
}
And the effect is, that always these two dates are different. But when i'm printing values of these two datas, i've got these same values:
System.out.println(dataSql);
System.out.println(myDataEntity.getDate);
Effect:
2012-11-16
2012-11-16
But, i found one issue:
if i make:
long date1 = dateSql.getTime(); // print 1353106800000
long date2 = myDataEntity.getDate().getTime(); // print 1353234605091
So how to compare two dates (yyyy-mm-dd) ?