Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
david Flores
748 PointsAccessing a database
Will Team Tree-house be creating a tutorial for accessing an existing SQlite database in Android?
7 Answers
Ben Jakuben
Treehouse TeacherHi David,
While this is something we definitely want to cover, we don't have anything in the pipeline in the next few months for it. Your best bet in the mean time is to check out a tutorial like this one from the Android Developer site.
I'm also gathering ideas for blog posts and will add this to the list. I'll post in here if I get that out any time soon. Thanks for the feedback! I really appreciating knowing what students like you are interested in seeing.
david Flores
748 PointsThank you soooo much for your answer. Looking foward to the video series. Let me know if I can help.
david Flores
748 PointsBen is it possible to have a SQLite Database with multiple entries and be able to extract one entry by matching columns and rows. All the examples i have come across on the web result in displaying entire rows or columns not just one (single) entry/result.
Ben Jakuben
Treehouse TeacherSorry, I'm not sure I understand. Can you give an example of what you mean using some example data?
david Flores
748 PointstableName = fruitPrices
_Id | Fruits | State | Price | 1 | Apples | CA | 0.30 | 2 | Pears | TX | 0.50 | 3 | Mango | CA | 0.60 |
I found the SQLite command to run a query and get just the price of the apple.
SELECT price FROM fruitPrices WHERE fruits = "Pears" //this would yield the price of the pear .50
now my question is how would I execute this into java so the answer will result in a specific text field
david Flores
748 Pointsnot sure what happened the table messed up. match the numbers under _Id and the rest will fall into place
david Flores
748 PointstableName = fruitPrices
_Id | Fruits | State | Price |
1 | Apples | CA | 0.30 |
2 | Pears | TX | 0.50 |
3 | Mango | CA | 0.60 |
hopefully this will do it
Ben Jakuben
Treehouse Teacher(Change those single quotes to back ticks and you're set! Click Edit to see how I changed it.)
I think your best bet at this point might be the tutorial from the Android developer site. This section specifically talks about how to read data: http://developer.android.com/training/basics/data-storage/databases.html#ReadDbRow
Once you get that cursor you can get the individual fields and store them in variables. Then you can use the variable to populate a TextView or EditText or wherever you need it.
david Flores
748 PointsThank you, now I assume that I will need of course the MainActivity Class, but would I need a DataHelper Class and possibly a Activity Helper Class? Now I have seen in other YouTube Videos that they are putting the results in another XML file, is this necessary or can i do it in one XML?
Thank you Ben I am sure you have much better things to do than to answer my questions. :-)
Ben Jakuben
Treehouse TeacherAnswering questions from students is one of the best parts of my job! :) I don't have a simple example to share, but you can create those helper classes as nested classes within your MainActivity if you want to keep it all together when getting started for the first time. I would try to follow the tutorial as closely as possible, or even build exactly what the tutorial shows as a separate project and then use it as a model for your own.
I don't know where XML comes into play. That must be specific to other things.