Win a copy of Get Programming with Java (MEAP only) this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

Viable Way To Copy SQLite Database To ArrayList?  RSS feed

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am creating a binded service to use for catching duplicates before they are written to my database.

In the service, I want to query everything from the database onStartCommand and write the results to an ArrayList that I can use in multiple methods with conditionals, etc.

Is there a viable way to achieve adding all of the database's records to an ArrayList?
 
Bartender
Posts: 1868
81
Android Chrome IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are a few different ways that you could do this.

You can do this the manual with lot of code, or you can do with use something like Room
http://www.vogella.com/tutorials/AndroidSQLite/article.html
Or possibly an other ORM.

I'll see if I can find an example, with the all of the extra coding/typing.
 
Pete Letkeman
Bartender
Posts: 1868
81
Android Chrome IntelliJ IDE Java MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here you go https://medium.com/wiselteach/android-sqlite-database-androidmonk-6b92d1bdf33b
Take a look at DBHandler.java which I've copied and pasted the part that may interest you below:

Please do not do a "SELECT * " as these types of queries are known to be slower then when you specify the fields explicitly.
With a small database this could be milliseconds, with distributed systems where the database is not on the same system this could add minutes or more.
 
Adam Wentz
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Pete Letkeman wrote:Here you go https://medium.com/wiselteach/android-sqlite-database-androidmonk-6b92d1bdf33b
Take a look at DBHandler.java which I've copied and pasted the part that may interest you



Yes! This seems to be what I was looking for. I have been scouring the web all the day and never came across this.

Thanks a bunch, Pete!  
 
Pete Letkeman
Bartender
Posts: 1868
81
Android Chrome IntelliJ IDE Java MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are welcome, I'm glad you find this information useful.
 
I think I'll just lie down here for a second. And ponder this tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!