This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

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?
 
Saloon Keeper
Posts: 1844
80
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
Saloon Keeper
Posts: 1844
80
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
Saloon Keeper
Posts: 1844
80
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!