I want to get the rows where date and time are greater then given date. Here is my table:
EvDate EvTime ClBdg Name Event
18.01.2015 10:55:01 001 Jane enter
18.01.2015 19:31:21 003 Brad exit
19.01.2015 13:31:21 002 Lucy exit
Given date
is 18.01.2015
, time
is 17:00:00
. Desired values are:
EvDate EvTime ClBdg Name Event
18.01.2015 19:31:21 003 Brad exit
19.01.2015 13:31:21 002 Lucy exit
Can anyone helps me?
Edit: To be more clear I edited my post. Here is the java code to execute the query:
private static final SimpleDateFormat sdfTime=new SimpleDateFormat("HH:mm:ss");
private static final SimpleDateFormat sdfDate=new SimpleDateFormat("dd.MM.yyyy");
private long givenTimeStamp = 1421600400L;
public static Date givenDate = new Date(givenTimeStamp);
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
String DATABASE = "jdbc:ucanaccess://"+CONF.getString("db.location")+";jackcessOpener=uz.lexus.access.crypto.MyCryptoProvider";
connection= DriverManager.getConnection(DATABASE, null, null);
List<Event> events=new ArrayList<Event>();
String selectEvents = "select EvDate,EvTime,ClBdg,Event from Evntlog_tbl where Event in ('enter','exit') and not ClBdg=0 and EvDate >= ? and EvTime > ? order by EvDate desc, EvTime desc";
PreparedStatement prstm= connection.prepareStatement(selectEvent);
java.sql.Date date=new java.sql.Date(sdfDate.parse(sdfDate.format()).getTime(givenDate));
java.sql.Time time=new Time(sdfTime.parse(sdfTime.format(givenDate)).getTime());
prstm.setDate(1,date);
prstm.setTime(2,time);
ResultSet rs = prstm.executeQuery();
Now the question is: Is the query in the selectEvent correct?
try this ,
As you have two different columns for Evdate
and EvTime
SELECT * FROM table_name WHERE EvDate >'18.01.2015' OR (EvDate = '18.01.2015' AND EvTime > '17:00:00'
Update-
attaching a fiddle , will be helpful .