wood burning stoves*
The moose likes Android and the fly likes Getting ArrayList from SQLite Database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Android
Bookmark "Getting ArrayList from SQLite Database" Watch "Getting ArrayList from SQLite Database" New topic
Author

Getting ArrayList from SQLite Database

Sarra Sakka
Ranch Hand

Joined: Jul 12, 2013
Posts: 272
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
Marshal

Joined: Mar 22, 2005
Posts: 41601
    
  55
Why do you think there is an error? TellTheDetails, and remember that we can't see what happens if you run this code.


Ping & DNS - my free Android networking tools app
Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

Not to mention that this query opens the door wide open for SQL injection.
Sarra Sakka
Ranch Hand

Joined: Jul 12, 2013
Posts: 272
because when i calculate the size of list i found it 0
or i have 7 elements !!
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14114
    
  16

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.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Sarra Sakka
Ranch Hand

Joined: Jul 12, 2013
Posts: 272
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

Joined: Jul 12, 2013
Posts: 272
There's a problem, always the size is 0 !!
Sarra Sakka
Ranch Hand

Joined: Jul 12, 2013
Posts: 272
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

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?


Steve
Sarra Sakka
Ranch Hand

Joined: Jul 12, 2013
Posts: 272
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

Joined: Jul 12, 2013
Posts: 272
Nobody can help me
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41601
    
  55
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

Joined: Jul 12, 2013
Posts: 272
It's work now !!
I changed <integer> by <Integer>
 
Consider Paul's rocket mass heater.
 
subject: Getting ArrayList from SQLite Database