Two Laptop Bag*
The moose likes JDBC and the fly likes returning all records from an sqlite3 database from a specific month and year Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "returning all records from an sqlite3 database from a specific month and year" Watch "returning all records from an sqlite3 database from a specific month and year" New topic
Author

returning all records from an sqlite3 database from a specific month and year

Greg Reeder
Ranch Hand

Joined: Jun 14, 2011
Posts: 99

hello,

I have an application that works with a SQLite3 database. This database, among other things, contains a list of records each of which contains an associated date. I want to be able to write a function for my java program that returns a list of these records that are associated with (for exampe) June 2011. I wrote one function in java that returns records between two specified specific dates, but there has to be a way to write an sql request that does it much easier. Does anyone know where I could find that out?

Thanks in advance,

Greg
Greg Reeder
Ranch Hand

Joined: Jun 14, 2011
Posts: 99

I think i just made the defining descovery. I can say "select * from tablename where dates > '2011-05' and dates < '2011-07'; This returns all records for may and june. I am assuming that that is because it registers '2011-05' to be the very first of the month of may rather than the last. Pretty logical, although that was not my first thought. I can now write a database access method requesting that this very query be used with the dates as a variable, but it would just have to be changed to '2011-06' and '2011-07'. I find it peculiar that I cannot just say dates = '2011-06', but even that is somewhat logical, just not easy. Any further ideas would be apreciated, but my acute problem is already solved.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30546
    
150

Greg,
I'm not sure if your solution is cross browser compatibility. In answer to your question, I'm not sure if there is a better solution, I've always created a date with the first of the month.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Greg Reeder
Ranch Hand

Joined: Jun 14, 2011
Posts: 99

Internet browsers play no role in the matter as it is a stand alone application. The dates are when a particular action takes place, and require a DAY_OF_MONTH field. But the solution I found works well.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: returning all records from an sqlite3 database from a specific month and year