Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting ArrayList from SQLite Database

 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to get an array list which contains the identifiant of all the product for each category, knowing that the table must be of type integer :


at add, I think that there is an error
can you help me to fix it !!
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you think there is an error? TellTheDetails, and remember that we can't see what happens if you run this code.
 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not to mention that this query opens the door wide open for SQL injection.
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
because when i calculate the size of list i found it 0
or i have 7 elements !!
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15492
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll have to do some debugging. I'd start with printing the exact query that's executed:

Does the query look like what you expected? When you do the same query manually against the database (with some database browser tool), do you get the expected result?

I don't know what API you're using to query the database, it doesn't look you're using the standard JDBC API.
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, is the same !!
but the problem is not there is at add :


About the API i don't use the JDBC API
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's a problem, always the size is 0 !!
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have now jumped from a standard Java question (accessing from an ArrayList) back into a new Android-specific question. Generally for each new question you should create a new thread, and put it in the proper location, so folks expecting Java questions don't see Android questions without context.

Here is my guess: or more of leading questions. What do you put INTO the database in the COL_PRODUCT_NAME? Can you show the insert statement? What type do you define the column? Did you change your database so it stopped holding ... oh let's say String and started holding Integers? When you did that did you remember to increment the database version and write a correct update method?
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to get an array list which contains the identifiant of all the product for each category,
here's the code:

COL_ID_PRODUCT: (type int) column which contains the identifiant for each product
TABLE_PRODUCT:contains COL_ID_PRODUCT,COL_PRODUCT_NAME which contains the name for each product, COL_CATEGORY (type int) contains the ID of the category to which each product belongs.

To test my method, i just want to calculate the size of this tab :

When i debug this, the size n is 0 or i have 7 product in the category with ID=1 !!

 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nobody can help me
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's probably because you're ignoring most of what people tell you. You didn't follow up on most of what Jesper and Steve suggested.
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's work now !!
I changed <integer> by <Integer>
 
Lovro Bajc
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have sort of the same problem. I need to obtain the data in Chart Activity from the database class and use it to populate chart. Since it is dynamic chart I created an ArrayList of Integers, however how to populate it with integers from database class I have no idea.

so far I have come up with a method in Chart calss:





Class getHappyData in the database should return the integers ArrayList HappyList. And here I have an issue how to obtain the integers and put them into HappyList in Chart.class.




any advice would be much appreciated.

thank you for your time.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic