• Post Reply Bookmark Topic Watch Topic
  • New Topic

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?
 
Rancher
Posts: 1164
30
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
Rancher
Posts: 1164
30
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
Rancher
Posts: 1164
30
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!