This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Can you check if your start time & end time should be swapped in logic?
Joined: Feb 10, 2008
Thank you John Jai for your response. Actually I am writing this code for a batch job. Where I have to retrieve only those rows from database, which were created within last 24 hours. This is my requirement.
So if today is August 22, 2011, I have to retrieve only those rows which were created August 21, 2011. Please let me know if you have any other question.
When working with complex data types, such as date, it's best to use the raw format and avoid strings if possible. For example, you can add an index to sort a column on a date making range queries, common in date queries, fast. Converting such values to strings, though, may trip up the query optimizer.
You can use a PreparedStatement and call setTimestamp() to set a value for your WHERE clause. In this case, I would use a Calendar object to get the date/time of the startTime you want to work with, 24 hours ago, and return all records > than it.
Thank you John Jai and Scott Selikoff. I used calendar object to calculate my start date and end date and formatted it with SimpleDateFormat. Everything is working fine. Thank you very much for the information.